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

[-Dnative] JPA class Person in integration-tests/spring-data-jpa uses j.u.Random #16018

Closed
jerboaa opened this issue Mar 25, 2021 · 6 comments · Fixed by #16020
Closed

[-Dnative] JPA class Person in integration-tests/spring-data-jpa uses j.u.Random #16018

jerboaa opened this issue Mar 25, 2021 · 6 comments · Fixed by #16020
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working
Milestone

Comments

@jerboaa
Copy link
Contributor

jerboaa commented Mar 25, 2021

Describe the bug

Person class in integration-tests/spring-data-jpa uses java.util.Random as part of its implementation. When generating a native-image from that app, this fails with graal 21.1-dev since Random is prohibited to end up in the native image heap (randomness would become predictable otherwise). The fix would be to runtime-initialize the class, but this turns out problematic since a generated JPA class, io.quarkus.it.spring.data.jpa.PersonRepository_bcb609283abd593bd6e8ce51955e38a20ba9d528Impl_Bean, triggers initialization of the class and would, thus, need to get runtime-initialized as well. It's not clear how this could be done since the generated class name is not predictable. I'd expect for this example to be a valid use-case and as it stands there doesn't seem to be a good solution available yet to solve this runtime initialization config problem.

Expected behavior

Have some way to allow for runtime initialized JPA-generated classes.

Actual behavior

No way to configure runtime initialization of generated classes

To Reproduce

  1. Get a graal vm 21.1-dev build. for example https://github.com/graalvm/graalvm-ce-dev-builds/releases/tag/21.1.0-dev-20210323_2140
  2. export GRAALVM_HOME=/path/to/21.1-dev/build
  3. ./mvnw verify -Dnative -Dquarkus.native.additional-build-args="--trace-class-initialization=io.quarkus.it.spring.data.jpa.Person,--initialize-at-run-time=io.quarkus.it.spring.data.jpa.Person,--trace-object-instantiation=java.util.Random" -pl integration-tests/spring-data-jpa/

Configuration

Tried with that to fix the runtime init problem, but that's insufficient.

quarkus.native.additional-build-args=--initialize-at-run-time=io.quarkus.it.spring.data.jpa.Person

Additional context

This fix didn't work. I guess a more elaborate, more generic fix is needed.

@jerboaa jerboaa added the kind/bug Something isn't working label Mar 25, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 25, 2021

/cc @geoand

@jerboaa
Copy link
Contributor Author

jerboaa commented Mar 25, 2021

Example stack trace:

[INFO] --- quarkus-maven-plugin:999-SNAPSHOT:build (default) @ quarkus-integration-test-spring-data-jpa ---
[INFO] [org.jboss.threads] JBoss Threads version 3.2.0.Final
[INFO] [org.hibernate.Version] HHH000412: Hibernate ORM core version 5.4.30.Final
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building native image source jar: /home/sgehwolf/Documents/openjdk/quarkus/quarkus-source/integration-tests/spring-data-jpa/target/quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-native-image-source-jar/quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Building native image from /home/sgehwolf/Documents/openjdk/quarkus/quarkus-source/integration-tests/spring-data-jpa/target/quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-native-image-source-jar/quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM Version 21.1.0-dev (Mandrel Distribution) (Java Version 11.0.11-ea+2)
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] /disk/graal/builds/graalvm-21.1-dev-2021-03-19-ServiceLocator/bin/native-image -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 -J-Duser.language=en -J-Duser.country=US -J-Dfile.encoding=UTF-8 --trace-class-initialization=io.quarkus.it.spring.data.jpa.Person --initialize-at-run-time=io.quarkus.it.spring.data.jpa.Person --trace-object-instantiation=java.util.Random --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -H:+AllowFoldMethods -jar quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:NativeLinkerOption=-no-pie -H:-UseServiceLoaderFeature -H:+StackTrace quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner
[quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner:14887]    classlist:   6,819.91 ms,  1.19 GB
[quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner:14887]        (cap):     700.52 ms,  1.19 GB
[quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner:14887]        setup:   3,527.52 ms,  1.19 GB
12:10:42,891 INFO  [org.hib.Version] HHH000412: Hibernate ORM core version 999-SNAPSHOT
12:10:42,897 INFO  [org.hib.ann.com.Version] HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
12:10:42,938 INFO  [org.hib.dia.Dialect] HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
[quarkus-integration-test-spring-data-jpa-999-SNAPSHOT-runner:14887]     analysis:  15,206.13 ms,  2.00 GB
Error: Classes that should be initialized at run time got initialized during image building:
 io.quarkus.it.spring.data.jpa.Person the class was requested to be initialized at run time (from the command line). io.quarkus.runner.ApplicationImpl caused initialization of this class with the following trace: 
	at io.quarkus.it.spring.data.jpa.Person.<clinit>(Person.java)
	at java.lang.Class.forName0(Unknown Source)
	at java.lang.Class.forName(Class.java:398)
	at io.quarkus.it.spring.data.jpa.PersonRepository_bcb609283abd593bd6e8ce51955e38a20ba9d528Impl_Bean.<init>(PersonRepository_bcb609283abd593bd6e8ce51955e38a20ba9d528Impl_Bean.zig:171)
	at io.quarkus.arc.setup.Default_ComponentsProvider.addBeans2(Default_ComponentsProvider.zig:646)
	at io.quarkus.arc.setup.Default_ComponentsProvider.getComponents(Default_ComponentsProvider.zig:43)
	at io.quarkus.arc.impl.ArcContainerImpl.<init>(ArcContainerImpl.java:112)
	at io.quarkus.arc.Arc.initialize(Arc.java:20)
	at io.quarkus.arc.runtime.ArcRecorder.getContainer(ArcRecorder.java:40)
	at io.quarkus.deployment.steps.ArcProcessor$generateResources-1025303321.deploy_0(ArcProcessor$generateResources-1025303321.zig:76)
	at io.quarkus.deployment.steps.ArcProcessor$generateResources-1025303321.deploy(ArcProcessor$generateResources-1025303321.zig:40)
	at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:240)


com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 io.quarkus.it.spring.data.jpa.Person the class was requested to be initialized at run time (from the command line). io.quarkus.runner.ApplicationImpl caused initialization of this class with the following trace: 
	at io.quarkus.it.spring.data.jpa.Person.<clinit>(Person.java)
	at java.lang.Class.forName0(Unknown Source)
	at java.lang.Class.forName(Class.java:398)
	at io.quarkus.it.spring.data.jpa.PersonRepository_bcb609283abd593bd6e8ce51955e38a20ba9d528Impl_Bean.<init>(PersonRepository_bcb609283abd593bd6e8ce51955e38a20ba9d528Impl_Bean.zig:171)
	at io.quarkus.arc.setup.Default_ComponentsProvider.addBeans2(Default_ComponentsProvider.zig:646)
	at io.quarkus.arc.setup.Default_ComponentsProvider.getComponents(Default_ComponentsProvider.zig:43)
	at io.quarkus.arc.impl.ArcContainerImpl.<init>(ArcContainerImpl.java:112)
	at io.quarkus.arc.Arc.initialize(Arc.java:20)
	at io.quarkus.arc.runtime.ArcRecorder.getContainer(ArcRecorder.java:40)
	at io.quarkus.deployment.steps.ArcProcessor$generateResources-1025303321.deploy_0(ArcProcessor$generateResources-1025303321.zig:76)
	at io.quarkus.deployment.steps.ArcProcessor$generateResources-1025303321.deploy(ArcProcessor$generateResources-1025303321.zig:40)
	at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:240)


	at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:545)
	at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:228)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$14(NativeImageGenerator.java:763)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:71)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:763)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:580)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$2(NativeImageGenerator.java:493)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
	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)
Error: Image build request failed with exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  58.675 s
[INFO] Finished at: 2021-03-25T12:10:57+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:999-SNAPSHOT:build (default) on project quarkus-integration-test-spring-data-jpa: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] 	[error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: java.lang.RuntimeException: Failed to build native image
[ERROR] 	at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:209)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] 	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:920)
[ERROR] 	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
[ERROR] 	at java.base/java.lang.Thread.run(Thread.java:834)
[ERROR] 	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] Caused by: java.lang.RuntimeException: Image generation failed. Exit code: 1
[ERROR] 	at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.imageGenerationFailed(NativeImageBuildStep.java:350)
[ERROR] 	at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:181)
[ERROR] 	... 10 more
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@geoand
Copy link
Contributor

geoand commented Mar 25, 2021

So this seems to just be an issue with the test class.
Can't we just remove the static modifier from the field and be done with it?

I mean the use case in the test is rather contrived anyway

@jerboaa
Copy link
Contributor Author

jerboaa commented Mar 25, 2021

Sure if you think this is not something user applications would run into too, then yeah sure.

@geoand
Copy link
Contributor

geoand commented Mar 25, 2021

Yeah, there is no need to have this sort of Random here.
Feel free to open a PR and I'll approve

jerboaa added a commit to jerboaa/quarkus that referenced this issue Mar 25, 2021
This reworks the test so that Person (an Entity class) no longer uses
j.u.Random directly, but delegates generation of random data to
a separate class which gets runtime-initialized.

Closes quarkusio#16018
@jerboaa
Copy link
Contributor Author

jerboaa commented Mar 25, 2021

Yeah, there is no need to have this sort of Random here.
Feel free to open a PR and I'll approve

Here you are: #16020

@quarkus-bot quarkus-bot bot added this to the 1.14 - main milestone Mar 25, 2021
@gsmet gsmet modified the milestones: 2.0.0.Alpha1, 1.13.4.Final May 10, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 10, 2021
This reworks the test so that Person (an Entity class) no longer uses
j.u.Random directly, but delegates generation of random data to
a separate class which gets runtime-initialized.

Closes quarkusio#16018

(cherry picked from commit b12f825)
juazugas pushed a commit to juazugas/quarkus that referenced this issue Sep 30, 2021
This reworks the test so that Person (an Entity class) no longer uses
j.u.Random directly, but delegates generation of random data to
a separate class which gets runtime-initialized.

Closes quarkusio#16018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants