7

When I build a native image for my application I have some errors that I don't understand.

    Error: unsupported features in 3 methods
    Detailed message:
    Error: com.oracle.svm.hosted.substitute.DeletedElementException:     Unsupported method java.lang.Class.getConstantPool() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class

Graal advise me to set this option --report-unsupported-elements-at-runtime

I read the code of NativeImageMojo

I'm trying to put something like:

  <plugin>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-maven-plugin</artifactId>
      <version>${quarkus.version}</version>
      <executions>
      <execution>
          <goals>
             <goal>native-image</goal>
          </goals>
      <configuration>
           <enableHttpUrlHandler>true</enableHttpUrlHandler>
           <containerRuntimeOptions>--report-unsupported-elements-at-runtime</containerRuntimeOptions>
      </configuration>
      </execution>
      </executions>
  </plugin>

But option does not appear:

[INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] /sandbox/Resources/GraalVm/graalvm-ce-1.0.0-rc15/bin/native-image -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar portfolio-app-1.0-SNAPSHOT-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:NativeLinkerOption=-no-pie -H:-SpawnIsolates -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace

How can I adding --report-unsupported-elements-at-runtime ? (I used Quarkus-bom 0.14.0 with graalvm-ce-1.0.0-rc15)

bmeynier
  • 289
  • 2
  • 12

3 Answers3

4

In this case, the best way to do it is to use:

<reportErrorsAtRuntime>true</reportErrorsAtRuntime>

In the configuration of your native-image goal.

Guillaume Smet
  • 9,921
  • 22
  • 29
  • Its work well, this param adding -H:+ReportUnsupportedElementsAtRuntime argument. Thx Guillaume – bmeynier Apr 27 '19 at 14:09
  • @bmeynier can you please accept this answer if it worked for you in order for future readers to easily know it is correct without having to read comments? Thanks! – geoand May 03 '19 at 12:13
4

Your two propositions work well but the stoud are not exacltly the same.
Option -H:+ReportUnsupportedElementsAtRuntime return:

Fatal error: java.lang.NoClassDefFoundError
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
        at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:459)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:288)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:422)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:108)
Caused by: java.lang.NoClassDefFoundError: javax/security/jacc/EJBMethodPermission
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.getDeclaredMethods(Class.java:1975)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:437)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:270)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:230)
        at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:865)
        at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:820)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:522)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:442)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: javax.security.jacc.EJBMethodPermission
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 15 more
Error: Image build request failed with exit status 1

Option --report-unsupported-elements-at-runtime return :

Fatal error: java.lang.NoClassDefFoundError
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
        at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:459)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:288)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:422)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:108)
Caused by: java.lang.NoClassDefFoundError: javax/security/jacc/PolicyContextException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.getDeclaredMethods(Class.java:1975)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:437)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:270)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:230)
        at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:865)
        at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:820)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:522)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:442)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: javax.security.jacc.PolicyContextException
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 15 more
Error: Image build request failed with exit status 1

I found some documentation

--report-unsupported-elements-at-runtime reports usage of unsupported methods and fields at run time when they are accessed the first time, instead of as an error during image building.

I find information about -H:+ReportUnsupportedElementsAtRuntime in this website

Report usage of unsupported methods and fields at run time when they are accessed the first time, instead of as an error during image building

Description is quite the same however I don't understand why the return is different.

bmeynier
  • 289
  • 2
  • 12
  • 8
    For the sake of completeness: I was getting exactly the same missing `javax.security.jacc` classes and the solution was to add the following dependency: ` org.jboss.spec.javax.security.jacc jboss-jacc-api_1.5_spec ` – Peter Palaga May 09 '19 at 08:40
  • 1
    thx @PeterPalaga this fixed my issue, too. However in my case I then ran into the next java.lang.NoClassDefFoundError, this time for com/sun/jna/LastErrorException. Can be fixed by adding net.java.dev.jna jna-platform5.3.1 – mika May 04 '21 at 16:59
  • @PeterPalaga thanks, this helped. However, I wonder why this is required only when building natively and what I did in my code that it doesn't work without the dependency? The build process feels very fragile. How is one supposed to know what else will break, just when trying to get an already working program to compile natively? I'd wish the process would be more stable and intuitive... – Marian Klühspies Mar 06 '22 at 09:54
3

You can use the additionalBuildArgs parameter:

<plugin>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-maven-plugin</artifactId>
  <version>${quarkus.version}</version>
  <executions>
  <execution>
    <goals>
       <goal>native-image</goal>
    </goals>
  <configuration>
     <enableHttpUrlHandler>true</enableHttpUrlHandler>
     <additionalBuildArgs>--report-unsupported-elements-at-runtime</additionalBuildArgs>
  </configuration>
  </execution>
  </executions>
</plugin>
Oleg Šelajev
  • 3,530
  • 1
  • 17
  • 25
  • It's work well too, it's adding --report-unsupported-elements-at-runtime argument to GraalVm. Thx Oleg – bmeynier Apr 27 '19 at 14:11