Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: java.lang.NullPointerException when using SQLite #22822

Closed
sesponda opened this issue Jan 12, 2022 · 10 comments
Assignees
Labels
area/native-image kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency
Milestone

Comments

@sesponda
Copy link

Describe the bug

Native compilation of a very small Quarkus app using SQLite causes an NPE in org.graalvm.compiler.java.BytecodeParser (full stack trace visible in the logs).

The bug report details are for Mac. I was also able to reproduce it using Linux (Linux lubu2 5.4.0-92-generic #103-Ubuntu SMP Fri Nov 26 16:13:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux)

Expected behavior

Native binary is built.

Actual behavior

NPE:

[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM 21.3.0 Java 11 CE (Java Version 11.0.13+7-jvmci-21.3-b05)
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] docker run --env LANG=C --rm -v /test/quarkus-npe-test/target/quarkus-npe-1-native-image-source-jar:/project:z --name build-native-NnjXI quay.io/quarkus/ubi-quarkus-native-image:21.3-java11 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Duser.language=en -J-Duser.country=AU -J-Dfile.encoding=UTF-8 -H:-ParseOnce -J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -H:+AllowFoldMethods -J-Djava.awt.headless=true -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http -H:-UseServiceLoaderFeature -H:+StackTrace quarkus-npe-1-runner -jar quarkus-npe-1-runner.jar
[quarkus-npe-1-runner:26]    classlist:   5,765.12 ms,  0.96 GB
[quarkus-npe-1-runner:26]        (cap):   1,515.44 ms,  0.94 GB
[quarkus-npe-1-runner:26]        setup:   5,143.21 ms,  0.94 GB
02:19:16,604 INFO  [org.jbo.threads] JBoss Threads version 3.4.2.Final
[quarkus-npe-1-runner:26]     (clinit):     681.80 ms,  1.60 GB
[quarkus-npe-1-runner:26]   (typeflow):   7,008.22 ms,  1.60 GB
[quarkus-npe-1-runner:26]    (objects):  18,751.23 ms,  1.60 GB
[quarkus-npe-1-runner:26]   (features):   6,650.65 ms,  1.60 GB
[quarkus-npe-1-runner:26]     analysis:  34,451.37 ms,  1.60 GB
[quarkus-npe-1-runner:26]     universe:   2,445.88 ms,  1.60 GB
[quarkus-npe-1-runner:26]      (parse):   3,252.06 ms,  1.60 GB
[quarkus-npe-1-runner:26]      compile:   3,278.11 ms,  1.60 GB
2 fatal errors detected:
Fatal error:org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: java.lang.NullPointerException
	at parsing org.sqlite.BusyHandler.<init>(BusyHandler.java:10)
	at method: void org.sqlite.BusyHandler.<init>()
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2624)
	at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:107)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3485)
	at com.oracle.svm.hosted.phases.HostedBytecodeParser.iterateBytecodesForBlock(HostedGraphBuilderPhase.java:195)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.handleBytecodeBlock(BytecodeParser.java:3437)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3282)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1145)
	at com.oracle.svm.hosted.phases.HostedBytecodeParser.build(HostedGraphBuilderPhase.java:139)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:84)
	at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:81)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:212)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
	at com.oracle.svm.hosted.code.CompileQueue.defaultParseFunction(CompileQueue.java:935)
	at com.oracle.svm.hosted.code.CompileQueue.doParse(CompileQueue.java:741)
	at com.oracle.svm.hosted.code.CompileQueue$ParseTask.run(CompileQueue.java:327)
	at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:188)
	at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:172)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.NullPointerException
	at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java.RegisterFinalizerNode.mayHaveFinalizer(RegisterFinalizerNode.java:105)
	at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.StandardGraphBuilderPlugins$34.apply(StandardGraphBuilderPlugins.java:988)
	at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.execute(InvocationPlugin.java:166)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.applyInvocationPlugin(BytecodeParser.java:2225)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.tryInvocationPlugin(BytecodeParser.java:2210)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.appendInvoke(BytecodeParser.java:1912)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeSpecial(BytecodeParser.java:1803)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeSpecial(BytecodeParser.java:1795)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5418)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3477)
	... 23 more
Fatal error:org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: java.lang.NullPointerException
	at parsing org.sqlite.Collation.<init>(Collation.java:46)
	at method: void org.sqlite.Collation.<init>()
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2624)
	at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:107)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3485)
	at com.oracle.svm.hosted.phases.HostedBytecodeParser.iterateBytecodesForBlock(HostedGraphBuilderPhase.java:195)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.handleBytecodeBlock(BytecodeParser.java:3437)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3282)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1145)
	at com.oracle.svm.hosted.phases.HostedBytecodeParser.build(HostedGraphBuilderPhase.java:139)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:84)
	at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:81)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:212)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
	at com.oracle.svm.hosted.code.CompileQueue.defaultParseFunction(CompileQueue.java:935)
	at com.oracle.svm.hosted.code.CompileQueue.doParse(CompileQueue.java:741)
	at com.oracle.svm.hosted.code.CompileQueue$ParseTask.run(CompileQueue.java:327)
	at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:188)
	at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:172)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.NullPointerException
	at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java.RegisterFinalizerNode.mayHaveFinalizer(RegisterFinalizerNode.java:105)
	at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.StandardGraphBuilderPlugins$34.apply(StandardGraphBuilderPlugins.java:988)
	at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.execute(InvocationPlugin.java:166)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.applyInvocationPlugin(BytecodeParser.java:2225)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.tryInvocationPlugin(BytecodeParser.java:2210)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.appendInvoke(BytecodeParser.java:1912)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeSpecial(BytecodeParser.java:1803)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeSpecial(BytecodeParser.java:1795)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5418)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3477)
	... 23 more
[quarkus-npe-1-runner:26]      [total]:  53,327.56 ms,  1.60 GB
# Printing build artifacts to: /project/quarkus-npe-1-runner.build_artifacts.txt
Error: Image build request failed with exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:07 min
[INFO] Finished at: 2022-01-12T13:19:44+11:00

How to Reproduce?

  1. Clone https://github.com/sesponda/quarkus-npe-test
  2. Execute ./mvnw clean package -Pnative -Dquarkus.native.container-build=true

Note: using -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel:21.3-java11 also fails with the same NPE.

Output of uname -a or ver

Darwin C02DQ1BTMD6V 20.6.0 Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:07 PST 2021; root:xnu-7195.141.14~1/RELEASE_X86_64 x86_64

Output of java -version

java version "17.0.1" 2021-10-19 LTS Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

GraalVM version (if different from Java)

ubi-quarkus-mandrel:21.3-java11

Quarkus version or git rev

2.6.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: /Users/sesponda/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4 Java version: 17.0.1, vendor: Oracle Corporation, runtime: /Users/sesponda/.sdkman/candidates/java/17.0.1-oracle Default locale: en_AU, platform encoding: UTF-8 OS name: "mac os x", version: "11.6.2", arch: "x86_64", family: "mac"

Additional information

No response

@sesponda sesponda added the kind/bug Something isn't working label Jan 12, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 12, 2022

/cc @Karm, @galderz, @zakkak

@zakkak zakkak self-assigned this Jan 12, 2022
@Sanne
Copy link
Member

Sanne commented Jan 12, 2022

Interesting compilation failure, thanks for the report!

I'll also mark this as an extension request, as we don't support SQLite currently.

@Sanne Sanne added the kind/extension-proposal Discuss and Propose new extensions label Jan 12, 2022
@Sanne
Copy link
Member

Sanne commented Jan 12, 2022

@sesponda could you briefly describe why you'd prefer to use SQLite rather than one of the already supported databases? That would help us triage and prioritize things: I know SQLite is pupular among Android developers but haven't seen much use (yet) among backend developers.

@zakkak
Copy link
Contributor

zakkak commented Jan 12, 2022

I tried reproducing this outside of Quarkus (and without kotlin) without lack.

import java.sql.DriverManager;

public class Main {
	public static void main(String[] args) {
		try {
			Class.forName("org.sqlite.JDBC");
			DriverManager.getConnection("jdbc:sqlite:./temp-db").createStatement();
			System.out.println("SUCCESS");
    	} catch (Throwable t) {
			System.out.println("FAILED");
		}
    }
}

Compiles (using --no-fallback -H:+ReportExceptionStackTraces --diagnostics-mode --initialize-at-build-time) and runs as expected.

Examining the class initialization report I also see that org.sqlite.BusyHandler and org.sqlite.Collation were both initialized at build time.

Update: adding -H:-ParseOnce reproduces the issue. I opennd an upstream GraalVM issue to track this.

@sesponda
Copy link
Author

@Sanne

could you briefly describe why you'd prefer to use SQLite

The project is a command-line tool that needs to process the output of a 3rd party app. Unfortunately, that output is an SQLite DB and I can't change this.

@zakkak

I've applied your build options to my Quarkus project:

  1. Adding the "as is" caused Error: Classes that should be initialized at run time got initialized during image building
  2. Restricting the init to the problematic class (--initialize-at-run-time=org.sqlite.BusyHandler) caused the same (original) NPE.
  3. Adding only -H:+ParseOnce to the Quarkus compilation build args fixed the problem. As per this code comment, the only negative effect is more memory consumption during the build time.

Considering we have a workaround (thanks, @zakkak) and that there is an upstream bug to track, I'm happy to close this ticket. Thank you for the prompt help.

@zakkak
Copy link
Contributor

zakkak commented Jan 12, 2022

As per this code comment, the only negative effect is more memory consumption during the build time.

Correct, and that's even not always true. So if you are not hitting any memory limits you should be OK.

I'm happy to close this ticket. Thank you for the prompt help.

I would prefer keeping this open till the upstream issue is fixed and Quarkus defaults to a GraalVM version that includes that fix.

@Sanne
Copy link
Member

Sanne commented Jan 12, 2022

@sesponda thanks for the context!

@gsmet gsmet added triage/upstream Used for issues which are caused by issues in upstream projects/dependency and removed kind/extension-proposal Discuss and Propose new extensions labels Jan 12, 2022
@geoand
Copy link
Contributor

geoand commented May 17, 2022

@zakkak it seems like this issue has been fixed in GraalVM. Do you know if the fix is included in 22.1? If so, then we should close this.

@zakkak
Copy link
Contributor

zakkak commented May 17, 2022

Yes, I confirm that the fix is included in 22.1.

@zakkak zakkak closed this as completed May 17, 2022
@geoand
Copy link
Contributor

geoand commented May 17, 2022

Thanks!

@geoand geoand added this to the 2.10 - main milestone May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency
Projects
None yet
Development

No branches or pull requests

5 participants