Skip to content

Native image generator ought to be able to ignore type errors from unloadable annotation attributes #597

Closed

Description

@dsyer

In Spring Boot we use this idiom a lot:

...
@Configuration
@Import({ JacksonHttpMessageConvertersConfiguration.class,
		GsonHttpMessageConvertersConfiguration.class,
		JsonbHttpMessageConvertersConfiguration.class })
public class HttpMessageConvertersAutoConfiguration {
...
}

and then

@Configuration
@ConditionalOnClass(Jsonb.class)
class JsonbHttpMessageConvertersConfiguration {
...
}

where Jsonb.class is often not available at runtime,

The @Import references classes whose annotations might not be inspectable at runtime, but since we never actually try to do that, it should be fine. In fact, typically, at most one of those 3 will be available (sometimes none). GraalVM barfs on this:

$ native-image -Dio.netty.noUnsafe=true -H:Name=target/mini -H:ReflectionConfigurationFiles=mini.json --report-unsupported-elements-at-runtime -cp $CP com.example.mini.MiniApplication --debug-attach=8000
Listening for transport dt_socket at address: 8000
   classlist:   8,484.46 ms
       (cap):   1,235.46 ms
       setup:   4,201.41 ms
    analysis: 205,917.07 ms
fatal error: java.lang.ArrayStoreException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
	at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:414)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:275)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:372)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:104)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
	at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
	at java.lang.Class.createAnnotationData(Class.java:3521)
	at java.lang.Class.annotationData(Class.java:3510)
	at java.lang.Class.getAnnotation(Class.java:3415)
	at jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.getAnnotation(HotSpotResolvedObjectTypeImpl.java:800)
	at com.oracle.svm.hosted.SVMHost.platformSupported(SVMHost.java:147)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.createType(AnalysisUniverse.java:201)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:193)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:170)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:69)
	at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaType0(UniverseMetaAccess.java:91)
	at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaType(UniverseMetaAccess.java:82)
	at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaType(AnalysisMetaAccess.java:45)
	at com.oracle.svm.hosted.ameta.HostedDynamicHubFeature.replace(HostedDynamicHubFeature.java:54)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:521)
	at com.oracle.graal.pointsto.ObjectScanner.scanArray(ObjectScanner.java:195)
	at com.oracle.graal.pointsto.ObjectScanner.doScan(ObjectScanner.java:276)
	at com.oracle.graal.pointsto.ObjectScanner.finish(ObjectScanner.java:312)
	at com.oracle.graal.pointsto.ObjectScanner.scanBootImageHeapRoots(ObjectScanner.java:81)
	at com.oracle.graal.pointsto.ObjectScanner.scanBootImageHeapRoots(ObjectScanner.java:63)
	at com.oracle.graal.pointsto.BigBang.checkObjectGraph(BigBang.java:585)
	at com.oracle.graal.pointsto.BigBang.finish(BigBang.java:556)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:674)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:397)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image building with exit status 1

The classes and instructions for how to build the jar and the classpath are in the usual place: https://github.com/dsyer/spring-boot-micro-apps/tree/func.

Activity

  1. changed the title [-]Native image generator ought to be able to ignore type errors from unloadable annotations[/-] [+]Native image generator ought to be able to ignore type errors from unloadable annotation attributes[/+] on Aug 7, 2018
  2. cstancu commented on Aug 7, 2018

    @cstancu
    Member

    For reference, we have seen this kind of error in micronaut. See: #470 (comment). The proposed solution is: #470 (comment).

  3. self-assigned this
    on Aug 7, 2018
  4. sdeleuze commented on Sep 25, 2018

    @sdeleuze
    Collaborator

    I am currently blocked in Spring Fu due to this issue, just doing ReactiveWebServerFactoryAutoConfiguration configuration = new ReactiveWebServerFactoryAutoConfiguration(); fails with the exception reported by @dsyer .

  5. cstancu commented on Sep 25, 2018

    @cstancu
    Member

    @sdeleuze we are working on a major refactoring of the logic that deals with incomplete class paths.

  6. graemerocher commented on Oct 23, 2018

    @graemerocher
    Member

    @cstancu it looks like this is an issue for Micronaut users now too with the addition of the processing of META-INF/services files automatically. Previous we could exclude some services to workaround this issue by manually generating the reflect.json now these META-INF/services files are automatically added due to 84dcb4e#diff-94f52964cecab0a25ac57a96aa80b97aR55

    Is there a way to disable the logic for META-INF/services files? If not can this be resolved, otherwise Micronaut users are hitting this problem with RC8:

    See micronaut-projects/micronaut-core#766

  7. cstancu commented on Oct 23, 2018

    @cstancu
    Member

    The automatic registration of services can be disabled with the -H:-UseServiceLoaderFeature option. Then you can fallback to your custom META-INF/services processing.

  8. added a commit that references this issue on Oct 24, 2018
  9. cstancu commented on Feb 8, 2019

    @cstancu
    Member

    This issue should be fixed as of RC12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions