Java 对于在映像运行时初始化或重新初始化的类,映像堆中不允许有实例:sun.security.provider.NativePRNG

Java 对于在映像运行时初始化或重新初始化的类,映像堆中不允许有实例:sun.security.provider.NativePRNG,java,graalvm,quarkus,Java,Graalvm,Quarkus,当我试图编译为本机时,我遇到了一个非常奇怪的错误。 以下是错误: 206853 [INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] Running Quarkus native-image plugin on OpenJDK GraalVM CE 1.0.0-rc15 206863 [INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] /opt/gra

当我试图编译为本机时,我遇到了一个非常奇怪的错误。 以下是错误:

206853 [INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] Running Quarkus native-image plugin on OpenJDK GraalVM CE 1.0.0-rc15
206863 [INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] /opt/graalvm/bin/native-image -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Drx.unsafe-disable=true -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar example-project-api-services-1.0-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+PrintAnalysisCallTree -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:-SpawnIsolates -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace
[example-project-api-services-1.0-runner:391]    classlist:  12,582.29 ms
[example-project-api-services-1.0-runner:391]        (cap):   1,021.83 ms
[example-project-api-services-1.0-runner:391]        setup:   2,121.29 ms
13:12:55,427 INFO  [org.hib.val.int.uti.Version] HV000001: Hibernate Validator 6.1.0.Alpha4
13:12:55,729 INFO  [io.sma.fau.HystrixInitializer] ### Init Hystrix ###
13:12:55,731 INFO  [io.sma.fau.DefaultHystrixConcurrencyStrategy] ### Privilleged Thread Factory used ###
13:12:55,731 INFO  [io.sma.fau.HystrixInitializer] Hystrix concurrency strategy used: DefaultHystrixConcurrencyStrategy
13:12:55,737 WARN  [com.net.con.sou.URLConfigurationSource] No URLs will be polled as dynamic configuration sources.
13:12:55,737 INFO  [com.net.con.sou.URLConfigurationSource] To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
13:12:55,761 INFO  [org.hib.Version] HHH000412: Hibernate Core {5.4.2.Final}
13:12:55,774 INFO  [org.hib.ann.com.Version] HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
13:12:55,799 INFO  [org.hib.dia.Dialect] HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL95Dialect
13:12:55,863 INFO  [io.sma.ope.api.OpenApiDocument] OpenAPI document initialized: io.smallrye.openapi.api.models.OpenAPIImpl@4878969e
13:12:57,347 INFO  [org.jbo.threads] JBoss Threads version 3.0.0.Alpha4
13:12:58,200 INFO  [com.arj.ats.arjuna] ARJUNA012170: TransactionStatusManager started on port 38873 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService
13:12:58,348 INFO  [org.xnio] XNIO version 3.7.0.Final
13:12:58,440 INFO  [org.xni.nio] XNIO NIO Implementation Version 3.7.0.Final
Warning: RecomputeFieldValue.ArrayIndexScale automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.arrayIndexScale(Class) was detected in the static initializer of rx.internal.util.unsafe.ConcurrentCircularArrayQueue. Detailed failure reason(s): Could not determine the field where the value produced by the call to sun.misc.Unsafe.arrayIndexScale(Class) for the array index scale computation is stored. The call is not directly followed by a field store or by a sign extend node followed directly by a field store. 
Warning: RecomputeFieldValue.ArrayBaseOffset automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.arrayBaseOffset(Class) was detected in the static initializer of rx.internal.util.unsafe.ConcurrentCircularArrayQueue. Detailed failure reason(s): Could not determine the field where the value produced by the call to sun.misc.Unsafe.arrayBaseOffset(Class) for the array base offset computation is stored. The call is not directly followed by a field store or by a sign extend node followed directly by a field store. 
Warning: RecomputeFieldValue.ArrayIndexScale automatic substitution failed. The automatic substitution registration was attempted because a call to sun.misc.Unsafe.arrayIndexScale(Class) was detected in the static initializer of rx.internal.util.unsafe.SpscUnboundedArrayQueue. Detailed failure reason(s): Could not determine the field where the value produced by the call to sun.misc.Unsafe.arrayIndexScale(Class) for the array index scale computation is stored. The call is not directly followed by a field store or by a sign extend node followed directly by a field store. 
[example-project-api-services-1.0-runner:391]     analysis:  88,298.64 ms
Printing call tree to /builds/orema/example-project/services/example-project-services/example-project-api-services/target/reports/call_tree_example-project-api-services-1.0-runner_20190517_131435.txt
Printing list of used classes to /builds/orema/example-project/services/example-project-services/example-project-api-services/target/reports/used_classes_example-project-api-services-1.0-runner_20190517_131441.txt
Printing list of used packages to /builds/orema/example-project/services/example-project-services/example-project-api-services/target/reports/used_packages_example-project-api-services-1.0-runner_20190517_131441.txt
Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.security.provider.NativePRNG
Detailed message:
Trace:  object java.security.SecureRandom
    method net.example-project.domain.collection.control.CollectionNumber.generate()
Call path from entry point to net.example-project.domain.collection.control.CollectionNumber.generate(): 
    at net.example-project.domain.collection.control.CollectionNumber.generate(CollectionNumber.java:24)
    at net.example-project.domain.collection.control.CollectionNumber_ClientProxy.generate(Unknown Source)
    at net.example-project.domain.collection.boundary.CollectionCreationContext.create(CollectionCreationContext.java:41)
    at net.example-project.domain.collection.boundary.CollectionCreationContext_Subclass.create$$superaccessor27(Unknown Source)
    at net.example-project.domain.collection.boundary.CollectionCreationContext_Subclass$$function$$51.apply(Unknown Source)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.SortedOps$RefSortingSink$$Lambda$425/239200789.accept(Unknown Source)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at io.smallrye.restclient.async.AsyncInvocationInterceptorHandler$Decorator.lambda$decorate$0(AsyncInvocationInterceptorHandler.java:48)
    at io.smallrye.restclient.async.AsyncInvocationInterceptorHandler$Decorator$$Lambda$559/661106985.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:748)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
    at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
--------------------------------------------------------------------------------------------
-- WARNING: The above stack trace is not a real stack trace, it is a theoretical call tree---
-- If an interface has multiple implementations SVM will just display one potential call  ---
-- path to the interface. This is often meaningless, and what you actually need to know is---
-- the path to the constructor of the object that implements this interface.              ---
-- Quarkus has attempted to generate a more meaningful call flow analysis below          ---
---------------------------------------------------------------------------------------------



Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit 331740
我认为这些日志说明了很多错误:
错误:对于在映像运行时初始化或重新初始化的类,映像堆中不允许有实例:sun.security.provider.NativePRNG

我在GraalVM的Github回购中发现了一些问题。

我想我应该在

因此,我编写了这段Java代码:

@BuildStep
公共运行时InitializedClassBuildItem secureRandom(){
返回新的RuntimeInitializedClassBuildItem(“sun.security.provider.NativePRNG”);
}

但是它不起作用。

因此,首先,使用
@BuildStep
仅在Quarkus增强阶段起作用:您需要处于扩展中,它才能起作用。它在应用程序代码中不起作用

其次,您需要延迟持有该字段的类的运行时初始化,因此在您的情况下,可能是
CollectionNumber

因此,我想补充一点:

<additionalBuildArgs>--delay-class-initialization-to-runtime=net.example-project.domain.collection.control.CollectionNumber</additionalBuildArgs>
--将类初始化延迟到运行时=net.example-project.domain.collection.control.CollectionNumber

到pom.xml中的本机映像阶段。

因此,首先,使用
@BuildStep
仅在Quarkus增强阶段有效:您需要在扩展中才能工作。它在应用程序代码中不起作用

其次,您需要延迟持有该字段的类的运行时初始化,因此在您的情况下,可能是
CollectionNumber

因此,我想补充一点:

<additionalBuildArgs>--delay-class-initialization-to-runtime=net.example-project.domain.collection.control.CollectionNumber</additionalBuildArgs>
--将类初始化延迟到运行时=net.example-project.domain.collection.control.CollectionNumber

到pom.xml中的本机映像阶段。

您可以通过如下方式使用Maven pom.xml为Quarkus本机构建传递其他构建参数(2021年):


您可以像这样使用Maven pom.xml为Quarkus本机构建传递其他构建参数(2021年):


我在maven插件中寻找类似的东西。有关于maven酒店的文件吗?现在没有。我们需要在某个地方发布Maven站点。我在Maven插件中寻找类似的东西。有关于maven酒店的文件吗?现在没有。我们需要在某个地方发布Maven站点。
--initialize-at-run-time=org.bouncycastle.jcajce.provider.drbg.DRBG\$Default\,org.bouncycastle.jcajce.provider.drbg.DRBG\$NonceAndIV --trace-object-instantiation=sun.security.provider.NativePRNG