Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraalVM native compilation of Spring Boot 3.4.2 fails with VMError$HostedError

Very basic app following the instructions at https://docs.spring.io/spring-boot/how-to/native-image/developing-your-first-application.html

No weird and wonderful dependencies or anything UPDATE pom.xml included

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.test</groupId>
    <artifactId>nativetest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>native</name>
    <description>native</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

mvn native:compile fails with Fatal error: com.oracle.svm.core.util.VMError$HostedError: com.oracle.svm.core.util.VMError$HostedError: New Method or Constructor found as reachable after static analysis: public org.springframework.boot.ssl.SslBundle org.springframework.boot.http.client.ClientHttpRequestFactorySettings.sslBundle()

$ java --version
openjdk 17.0.5 2022-10-18 LTS
OpenJDK Runtime Environment GraalVM 22.3.0 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM GraalVM 22.3.0 (build 17.0.5+8-LTS, mixed mode, sharing)

Do I need to do something different/not mentioned in the spring tutorial to get the native compilation to work?

Perhaps some mvn or pom changes required?

Can anyone assist with some steps to get the below command to succeed, please?

Is there perhaps a different spring-boot version that works better with graalvm native build? UPDATE: spring-boot-starter-parent version 3.3.8 build succeeds, so issue seems to only affect 3.4.2

$ ./mvnw -Pnative -DskipTests clean native:compile
...
...
...
[1/7] Initializing...                                                                                    (2.3s @ 0.25GB)
 Version info: 'GraalVM 22.3.0 Java 17 CE'
 Java version info: '17.0.5+8-LTS'
 C compiler: gcc (linux, x86_64, 13.3.0)
 Garbage collector: Serial GC
 1 user-specific feature(s)
 - org.springframework.aot.nativex.feature.PreComputeFieldFeature
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
[2/7] Performing analysis...  [********]                                                                (13.3s @ 3.34GB)
  16,725 (92.41%) of 18,098 classes reachable
  27,019 (67.57%) of 39,988 fields reachable
  79,131 (62.19%) of 127,242 methods reachable
   1,021 classes,   353 fields, and 5,776 methods registered for reflection
      64 classes,    70 fields, and    55 methods registered for JNI access
       4 native libraries: dl, pthread, rt, z
[3/7] Building universe...                                                                               (2.2s @ 2.44GB)
[4/7] Parsing methods...      [*]                                                                        (1.4s @ 3.62GB)
[5/7] Inlining methods...     [****]                                                                     (0.9s @ 2.30GB)
[6/7] Compiling methods...    [***]                                                                      (9.4s @ 4.24GB)
[7/7] Creating image...
                                                                                  (0.0s @ 2.08GB)
Fatal error: com.oracle.svm.core.util.VMError$HostedError: com.oracle.svm.core.util.VMError$HostedError: New Method or Constructor found as reachable after static analysis: public org.springframework.boot.ssl.SslBundle org.springframework.boot.http.client.ClientHttpRequestFactorySettings.sslBundle()
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:72)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:696)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
Caused by: com.oracle.svm.core.util.VMError$HostedError: New Method or Constructor found as reachable after static analysis: public org.springframework.boot.ssl.SslBundle org.springframework.boot.http.client.ClientHttpRequestFactorySettings.sslBundle()
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:68)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.reflect.ReflectionFeature.getOrCreateAccessor(ReflectionFeature.java:121)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.target.ExecutableAccessorComputer.transform(ExecutableAccessorComputer.java:43)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.ComputedValueField.computeValue(ComputedValueField.java:343)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.ComputedValueField.readValue(ComputedValueField.java:313)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.meta.ReadableJavaField.readFieldValue(ReadableJavaField.java:38)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readValue(AnalysisConstantReflectionProvider.java:97)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.meta.HostedField.readValue(HostedField.java:161)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.addObjectToImageHeap(NativeImageHeap.java:439)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.addObject(NativeImageHeap.java:295)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.processAddObjectWorklist(NativeImageHeap.java:598)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.addTrailingObjects(NativeImageHeap.java:198)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:678)
    ... 4 more
------------------------------------------------------------------------------------------------------------------------
                        1.7s (5.0% of total time) in 41 GCs | Peak RSS: 6.73GB | CPU load: 16.70
========================================================================================================================
like image 699
capitalgsw Avatar asked Oct 16 '25 13:10

capitalgsw


1 Answers

$ java --version
openjdk 17.0.14 2025-01-21 LTS
OpenJDK Runtime Environment Liberica-NIK-23.0.7-1 (build 17.0.14+10-LTS)
OpenJDK 64-Bit Server VM Liberica-NIK-23.0.7-1 (build 17.0.14+10-LTS, mixed mode, sharing)

Using version 23.0.7.r17-nik VM solves this. So tutorial is slightly wrong (it says to use 22.3.r17-nik)

Thanks to @Dmitriy for the assist

like image 70
capitalgsw Avatar answered Oct 19 '25 04:10

capitalgsw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!