oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.34k stars 1.63k forks source link

[GR-52021] Getting NullPointerException instead of something that tells me what is wrong #8354

Closed tomasbjerre closed 8 months ago

tomasbjerre commented 8 months ago

Describe the issue

I am getting an NPE during ./gradlew nativeBuild with a Springboot 3.2.2 app. I would suggest changing the code to avoid NPE and instead throw some exception that describes what is wrong.

Gradle will run command /opt/mandrel/bin/native-image -cp xxx -H:+ReportExceptionStackTraces

Steps to reproduce the issue Sorry, cannot supply this information.

Describe GraalVM and your environment:

I know you want me to test with latest versions here, but I am unable to do that because this happens within an organization that does not provide more recent versions.

Error: java.util.concurrent.ExecutionException: com.oracle.svm.hosted.annotation.AnnotationMetadata$AnnotationExtractionError: java.lang.reflect.InvocationTargetException
com.oracle.graal.pointsto.util.AnalysisError: java.util.concurrent.ExecutionException: com.oracle.svm.hosted.annotation.AnnotationMetadata$AnnotationExtractionError: java.lang.reflect.InvocationTargetException
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisError.shouldNotReachHere(AnalysisError.java:169)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:66)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$postTask$13(ImageHeapScanner.java:755)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:187)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:171)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1423)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
    at java.base/java.util.concurrent.ForkJoinPool.externalHelpQuiesce(ForkJoinPool.java:2260)
    at java.base/java.util.concurrent.ForkJoinPool.helpQuiescePool(ForkJoinPool.java:2297)
    at java.base/java.util.concurrent.ForkJoinPool.awaitQuiescence(ForkJoinPool.java:3565)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.complete(CompletionExecutor.java:237)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis.doTypeflow(PointsToAnalysis.java:527)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis.finish(PointsToAnalysis.java:515)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:160)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:767)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:582)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:539)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:408)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:612)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:134)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:94)
Caused by: java.util.concurrent.ExecutionException: com.oracle.svm.hosted.annotation.AnnotationMetadata$AnnotationExtractionError: java.lang.reflect.InvocationTargetException
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:64)
    ... 19 more
Caused by: com.oracle.svm.hosted.annotation.AnnotationMetadata$AnnotationExtractionError: java.lang.reflect.InvocationTargetException
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor.findRoot(SubstrateAnnotationExtractor.java:466)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor.getAnnotationData(SubstrateAnnotationExtractor.java:188)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor.extractAnnotation(SubstrateAnnotationExtractor.java:123)
    at org.graalvm.sdk/org.graalvm.nativeimage.AnnotationAccess.getAnnotation(AnnotationAccess.java:96)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.SVMHost.platformSupported(SVMHost.java:806)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.SVMHost.platformSupported(SVMHost.java:776)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.createType(AnalysisUniverse.java:228)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:220)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:197)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.<init>(AnalysisMethod.java:157)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.PointsToAnalysisMethod.<init>(PointsToAnalysisMethod.java:70)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.PointsToAnalysisFactory.createMethod(PointsToAnalysisFactory.java:35)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.createMethod(AnalysisUniverse.java:453)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:441)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:417)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:78)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaMethod(UniverseMetaAccess.java:112)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaMethod(AnalysisMetaAccess.java:82)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.reflect.ReflectionFeature.createAccessor(ReflectionFeature.java:187)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.reflect.ReflectionFeature.getOrCreateAccessor(ReflectionFeature.java:141)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.target.ExecutableAccessorComputer.transform(ExecutableAccessorComputer.java:43)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.ComputedValueField.computeValue(ComputedValueField.java:359)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.ComputedValueField.readValue(ComputedValueField.java:329)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readHostedFieldValue(AnalysisConstantReflectionProvider.java:162)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.heap.SVMImageHeapScanner.readHostedFieldValue(SVMImageHeapScanner.java:122)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageHeapScanner.createImageHeapObject(ImageHeapScanner.java:373)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$getOrCreateConstantReachableTask$2(ImageHeapScanner.java:214)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageHeapScanner.getOrCreateConstantReachableTask(ImageHeapScanner.java:226)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.heap.SVMImageHeapScanner.getOrCreateConstantReachableTask(SVMImageHeapScanner.java:95)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageHeapScanner.scanEmbeddedRoot(ImageHeapScanner.java:116)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.registerEmbeddedRoot(AnalysisUniverse.java:563)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.registerEmbeddedRoot(MethodTypeFlowBuilder.java:408)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.registerUsedElements(MethodTypeFlowBuilder.java:317)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:235)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:583)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:165)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:152)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraphInfo(MethodTypeFlow.java:110)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.lambda$update$0(DefaultStaticInvokeTypeFlow.java:67)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.LightImmutableCollection.forEach(LightImmutableCollection.java:90)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.update(DefaultStaticInvokeTypeFlow.java:66)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:474)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:187)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:171)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1423)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:116)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor.findRoot(SubstrateAnnotationExtractor.java:457)
    ... 52 more
Caused by: java.lang.NullPointerException: Cannot invoke "java.io.InputStream.read(byte[], int, int)" because "in" is null
    at com.sun.xml.ws.util.MethodUtil.readAllBytes(MethodUtil.java:165)
    at com.sun.xml.ws.util.MethodUtil.findClass(MethodUtil.java:148)
    at java.base/java.lang.ClassLoader.findClass(ClassLoader.java:750)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:633)
    at java.base/java.lang.Package.getPackageInfo(Package.java:432)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ... 54 more
kassifar commented 8 months ago

Hi @tomasbjerre, thank you for reaching out. Unfortunately, there isn't enough information for us to be able to debug this issue. If you can provide us with a reproducer that is safe to share that would be helpful.

tomasbjerre commented 8 months ago

I think it is possible to add more information in this exception without me providing a reproduceable example.

I can trace it to: https://github.com/oracle/graal/blob/0d67c739da8f4ee40ed9796185205ed54935c06b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java#L466C23-L466C48

Perhaps throw new AnnotationExtractionError(e); can be changed to throw new AnnotationExtractionError(message,e);. Where message contains information from AnnotatedElement element. That would hopefully give users something to work with. Perhaps it would tell me some specific class in some specific library is the culprit.

I am not expecting you to solve my actual problem here, I just think you can provide a better error.

Feel free to close the issue if you disagree with this. I cannot provide more information.

kassifar commented 8 months ago

@fniephaus should I create a GR for this ?

fniephaus commented 8 months ago

Thanks for raising this, @tomasbjerre. Sure, we could extend the error message as you suggested. It would still be interesting to know if this is caused by normal end-user code or because you are accessing SVM internals?

Also, have you checked that throw new AnnotationExtractionError(message, e); actually helps you find the issue?

BTW: Why are you using a Quarkus builder image and Mandrel for building a Spring Boot application?

tomasbjerre commented 8 months ago

I am new to Graalvm, I don't know what SVM internals are. I would suggest you include enough information in the error in order to determine that.

No I have not checked if it would help me. That would mean debugging Graalvm during the build? I cannot do that.

I am using the Quarkus image and Mandrel because that is what my organization provides.

fniephaus commented 8 months ago

I am new to Graalvm, I don't know what SVM internals are. I would suggest you include enough information in the error in order to determine that.

Ok, good to know. Could you at least hint at what you've done to run into this issue? Instead of blindly changing errors, I'd like to actually confirm that we have made the error better.

tomasbjerre commented 8 months ago

This is our first attempt at trying to use Graalvm and Spring Native. So we have not really changed anything. I tried to compile "ahead of time" and also run that with ./gradlew bootRun -Pspring.aot.enabled=true and that works well on OpenJDK 17.0.2.

I think you should blindly change errors. I think both users, and you, would benefit of providing clear errors in all three throws in that findRoot method. I don't see why you would want to hide information like you currently do.

...
        } catch (InvocationTargetException e) {
            Throwable targetException = e.getTargetException();
            if (targetException instanceof LinkageError) {
                throw (LinkageError) targetException;
            }
            throw new AnnotationExtractionError(e);
        } catch (IllegalAccessException e) {
            throw new AnnotationExtractionError(e);
        }
...
tomasbjerre commented 8 months ago

I noticed that if I remove this dependency:

implementation "com.sun.xml.ws:jaxws-rt:4.0.1"

I will get a successful build. But will later get a ClassNotFoundException at runtime: Caused by: javax.xml.ws.WebServiceException: Provider com.sun.xml.internal.ws.spi.ProviderImpl not found.

I was able to successfully build and run another one of our apps using the same build chain (Tekton pipeline, Gradle version and Gradle script). I tried adding that dependency to that app, it still worked.

But still, the real issue here is the NPE and it would be really nice to know something about AnnotatedElement in the error.

fniephaus commented 8 months ago

8400 is already in the merge queue. You'll need to build from source though if you want to test it today, or wait a few days for a dev build.

tomasbjerre commented 5 months ago

I can only find the fix (419d06cd17f1c686551d139476944fab4b4749db) in master.

When can we expect this to be released and what version?

fniephaus commented 2 months ago

This fix will ship with the release of GraalVM for JDK 23 on September 17, 2024. In the meantime, you can use an EA build for JDK 23 or JDK 24.