当前位置: 首页 > 知识库问答 >
问题:

使用optaplanner构建quarkus本机映像时出现随机/可拆分随机错误

郭兴文
2023-03-14

在本机映像中构建quarkus optaplanner应用程序时,我遇到此“Random/SplittableRandom”错误:

docker run--env LANG=C--rm-v/Users/user1/myapp/target/myapp-1.0.0-SNAPSHOT-native-image-source-jar:/project:z--name build native qOeJv quay。io/quarkus/ubi quarkus本机映像:22.0.0-java11-J-Dsun。尼奥。ch.MaxUpdaterRaySize=100-J-Djava。util。登录中。manager=org。jboss。后勤经理。LogManager-J-Dvertex。记录器委托工厂类名=io。夸克斯。维特斯。果心运行时。VertxLogDelegateFactory-J-Dvertx。disableDnsResolver=true-J-Dio。内蒂。泄漏检测。级别=禁用-J-Dio。内蒂。分配器。maxOrder=3-J-Duser。语言=en-J-Duser。国家=美国-J-D文件。encoding=UTF-8-H:-ParseOnce-J--add exports=java。安全jgss/太阳。安全krb5=ALL-UNNAMED-J--add opens=java。base/java。text=ALL-UNNAMED-H:InitialCollectionPolicy=com。神谕svm。果心根斯卡文格。CollectionPolicy\$BySpaceAndTime-H:JNI-H:AllowFoldMethods-J-Djava。awt。headless=true-H:FallbackThreshold=0-H:ReportExceptionStackTraces-H:-AddAllCharsets-H:EnableURLProtocols=http,https-H:InlineBeforeAnalysis-H:-UseServiceLoaderFeature-H:StackTrace myapp-1.0.0-SNAPSHOT-runner-jar myapp-1.0.0-SNAPSHOT-runner。jar

Error: Unsupported features in 2 methods
Detailed message:
Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field java.util.Collections.r
Error: No instances of java.io.FilePermission are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.io.FilePermission.
Trace: Object was reached by 
    reading field java.util.concurrent.ConcurrentHashMap$Node.val of
        constant java.util.concurrent.ConcurrentHashMap$Node@2fa9569c reached by 
    indexing into array
        constant java.util.concurrent.ConcurrentHashMap$Node[]@37a65cb2 reached by 
    reading field java.util.concurrent.ConcurrentHashMap.table of
        constant java.util.concurrent.ConcurrentHashMap@2ade02d0 reached by 
    reading field java.io.FilePermissionCollection.perms of
        constant java.io.FilePermissionCollection@7a8b93fb reached by 
    reading field java.util.concurrent.ConcurrentHashMap$Node.val of
        constant java.util.concurrent.ConcurrentHashMap$Node@7cdf033 reached by 
    indexing into array
        constant java.util.concurrent.ConcurrentHashMap$Node[]@1a17f87 reached by 
    reading field java.util.concurrent.ConcurrentHashMap.table of
        constant java.util.concurrent.ConcurrentHashMap@3c16c45b reached by 
    reading field java.security.Permissions.permsMap of
        constant java.security.Permissions@51058af3 reached by 
    reading field java.security.ProtectionDomain.permissions of
        constant java.security.ProtectionDomain@14be23e7 reached by 
    scanning method org.drools.wiring.dynamic.PackageClassLoader.writeClass(PackageClassLoader.java:138)
Call path from entry point to org.drools.wiring.dynamic.PackageClassLoader.writeClass(String, byte[]): 
    at org.drools.wiring.dynamic.PackageClassLoader.writeClass(PackageClassLoader.java:138)
    at org.drools.wiring.dynamic.PackageClassLoader.internalDefineClass(PackageClassLoader.java:108)
    at org.drools.wiring.dynamic.PackageClassLoader.fastFindClass(PackageClassLoader.java:79)
    at org.drools.wiring.dynamic.PackageClassLoader.loadClass(PackageClassLoader.java:56)
    at com.oracle.svm.core.jdk.Target_java_lang_ClassLoader.loadClass(Target_java_lang_ClassLoader.java:141)
    at org.drools.ancompiler.KieBaseUpdaterANC.loadFromKJar(KieBaseUpdaterANC.java:86)
    at org.drools.ancompiler.KieBaseUpdaterANC.run(KieBaseUpdaterANC.java:56)
    at java.lang.Thread.run(Thread.java:829)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)
    at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

com.oracle.svm.core.util.UserError$UserException: Unsupported features in 2 methods
Detailed message:
Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field java.util.Collections.r
Error: No instances of java.io.FilePermission are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.io.FilePermission.
Trace: Object was reached by 
    reading field java.util.concurrent.ConcurrentHashMap$Node.val of
        constant java.util.concurrent.ConcurrentHashMap$Node@2fa9569c reached by 
    indexing into array
        constant java.util.concurrent.ConcurrentHashMap$Node[]@37a65cb2 reached by 
    reading field java.util.concurrent.ConcurrentHashMap.table of
        constant java.util.concurrent.ConcurrentHashMap@2ade02d0 reached by 
    reading field java.io.FilePermissionCollection.perms of
        constant java.io.FilePermissionCollection@7a8b93fb reached by 
    reading field java.util.concurrent.ConcurrentHashMap$Node.val of
        constant java.util.concurrent.ConcurrentHashMap$Node@7cdf033 reached by 
    indexing into array
        constant java.util.concurrent.ConcurrentHashMap$Node[]@1a17f87 reached by 
    reading field java.util.concurrent.ConcurrentHashMap.table of
        constant java.util.concurrent.ConcurrentHashMap@3c16c45b reached by 
    reading field java.security.Permissions.permsMap of
        constant java.security.Permissions@51058af3 reached by 
    reading field java.security.ProtectionDomain.permissions of
        constant java.security.ProtectionDomain@14be23e7 reached by 
    scanning method org.drools.wiring.dynamic.PackageClassLoader.writeClass(PackageClassLoader.java:138)
Call path from entry point to org.drools.wiring.dynamic.PackageClassLoader.writeClass(String, byte[]): 
    at org.drools.wiring.dynamic.PackageClassLoader.writeClass(PackageClassLoader.java:138)
    at org.drools.wiring.dynamic.PackageClassLoader.internalDefineClass(PackageClassLoader.java:108)
    at org.drools.wiring.dynamic.PackageClassLoader.fastFindClass(PackageClassLoader.java:79)
    at org.drools.wiring.dynamic.PackageClassLoader.loadClass(PackageClassLoader.java:56)
    at com.oracle.svm.core.jdk.Target_java_lang_ClassLoader.loadClass(Target_java_lang_ClassLoader.java:141)
    at org.drools.ancompiler.KieBaseUpdaterANC.loadFromKJar(KieBaseUpdaterANC.java:86)
    at org.drools.ancompiler.KieBaseUpdaterANC.run(KieBaseUpdaterANC.java:56)
    at java.lang.Thread.run(Thread.java:829)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)
    at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

    at com.oracle.svm.core.util.UserError.abort(UserError.java:87)
    at com.oracle.svm.hosted.FallbackFeature.reportAsFallback(FallbackFeature.java:233)
    at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:731)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:537)
    at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:494)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:426)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:587)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:126)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:617)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported features in 2 methods
Detailed message:
Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field java.util.Collections.r
Error: No instances of java.io.FilePermission are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.io.FilePermission.
Trace: Object was reached by 
    reading field java.util.concurrent.ConcurrentHashMap$Node.val of
        constant java.util.concurrent.ConcurrentHashMap$Node@2fa9569c reached by 
    indexing into array
        constant java.util.concurrent.ConcurrentHashMap$Node[]@37a65cb2 reached by 
    reading field java.util.concurrent.ConcurrentHashMap.table of
        constant java.util.concurrent.ConcurrentHashMap@2ade02d0 reached by 
    reading field java.io.FilePermissionCollection.perms of
        constant java.io.FilePermissionCollection@7a8b93fb reached by 
    reading field java.util.concurrent.ConcurrentHashMap$Node.val of
        constant java.util.concurrent.ConcurrentHashMap$Node@7cdf033 reached by 
    indexing into array
        constant java.util.concurrent.ConcurrentHashMap$Node[]@1a17f87 reached by 
    reading field java.util.concurrent.ConcurrentHashMap.table of
        constant java.util.concurrent.ConcurrentHashMap@3c16c45b reached by 
    reading field java.security.Permissions.permsMap of
        constant java.security.Permissions@51058af3 reached by 
    reading field java.security.ProtectionDomain.permissions of
        constant java.security.ProtectionDomain@14be23e7 reached by 
    scanning method org.drools.wiring.dynamic.PackageClassLoader.writeClass(PackageClassLoader.java:138)
Call path from entry point to org.drools.wiring.dynamic.PackageClassLoader.writeClass(String, byte[]): 
    at org.drools.wiring.dynamic.PackageClassLoader.writeClass(PackageClassLoader.java:138)
    at org.drools.wiring.dynamic.PackageClassLoader.internalDefineClass(PackageClassLoader.java:108)
    at org.drools.wiring.dynamic.PackageClassLoader.fastFindClass(PackageClassLoader.java:79)
    at org.drools.wiring.dynamic.PackageClassLoader.loadClass(PackageClassLoader.java:56)
    at com.oracle.svm.core.jdk.Target_java_lang_ClassLoader.loadClass(Target_java_lang_ClassLoader.java:141)
    at org.drools.ancompiler.KieBaseUpdaterANC.loadFromKJar(KieBaseUpdaterANC.java:86)
    at org.drools.ancompiler.KieBaseUpdaterANC.run(KieBaseUpdaterANC.java:56)
    at java.lang.Thread.run(Thread.java:829)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)
    at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

    at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:129)
    at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:728)
    ... 6 more

我搜索,有这篇文章与randoms原生图像,但我仍然不知道我需要做什么来解决这个问题。

似乎quarkus试图为drools类创建Random或SplittableRandom的实例,我使用optaplanner quarkus,我不使用drools规则引擎,我使用约束流。

在为optaplanner quarkus应用程序构建本机映像时,是否有人遇到同样的问题?我该怎么克服这个问题?我试过graalvm 22.0和21.3,它们都有相同的问题。

提前谢谢你的帮助。

共有1个答案

华安民
2023-03-14

下面这行代码告诉我你的类路径有问题:

Call path from entry point to org.drools.wiring.dynamic.PackageClassLoader.writeClass(String, byte[]): 

drools wiring dynamic模块不是为在本机模式下工作而设计的,需要用drools wiring static替换。实际上,optaplanner quarkus模块为您完成所有这些工作。

您是否使用optaplanner-qukus而不是optaplanner-core?堆栈跟踪告诉我您可能不是。如果您是,我建议您找出drools-布线-动态依赖关系的来源,并将其删除。

问题的另一个来源可能是您试图在本机模式下使用constraint DRL。这是不受支持的,并且会因一个或另一个异常而失败。在本机模式下,您有三种约束选择——约束流、Java增量或Java Easy。

 类似资料:
  • 我正在尝试使用Github自托管运行程序为我的qukus应用程序构建原生映像。 这对我来说在Github托管的跑步者上非常有用,但我想在自托管的跑步者上这样做,这样我们就不会浪费Github的预算。 当我更新我的工作流程以使用自我托管的跑步者时,我开始遇到这个奇怪的异常。 我使用的是GraalVM 22.0.0.2、Java 11.0.14、Maven 3.8.4和Quarkus 2.7.5 我尝

  • 亲爱的,我下面的原生图像构建教程由Quarkus创建原生graalvm,但我得到了下面的错误: 我的环境:OS:CentOS 7 Quarkus:0.11.0 Java:Open JDK 1.8.0_181 GraalVM:1.0.0-rc13 使用quarkus在你的应用程序中没有主要方法,但如何使用graal原生图像使其工作?

  • 有可能在Java 16下构建本机Quarkus映像吗?没有找到任何操作说明。 不知何故,这应该是可能的,因为Oracle发布了对Java16的GraalVM支持(https://www.graalvm.org/release-notes/21_1/)

  • 我有以下简化设置: 4)应用程序.属性 当我使用本机maven配置文件(mvn clean package-pnative)运行该文件时,我得到: 使用--report-unsupport-elements-at-runtime运行它也没有太大帮助。当我删除MyEntity类时,它在Mac+GRAALVM-CE-Java11-20.0.0上成功地编译为本机可执行文件

  • 我正在使用GraalVm 21.0.0.2的native-image-maven-plugin为JavaFX应用程序创建一个本机映像。当我尝试在构建成功结束后执行它时,我得到以下错误: 我很感激你能给我的任何帮助。

  • 我试图用Kotlin构建一个使用Kotlin的简单应用程序。随机的GraalVM本机映像上的随机类。但这在运行时失败。见下文。 作为解决方法,您可以使用java标准java.util.Random类。 有人能告诉我怎么用Kotlin型吗? 应用程序。kt 文档 运行时错误 这里是最小的工作示例项目