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

[Native Image] Error: java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/MyService (class file version 67.65535). Try running with '--enable-preview' #10647

Open
1 task done
patpatpat123 opened this issue Feb 10, 2025 · 5 comments
Assignees

Comments

@patpatpat123
Copy link

Describe the Issue

Hello team,

I have a java 23 springboot 3 app, following Alina Yurenko tutorial

The thing is I am using preview features in my code. In my case, I am using structured task scope, which is a feature still in preview in Java 23.

With that said, I did configure the pom to enable preview features, but the build is still failing.

  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <compilerArguments>--enable-preview</compilerArguments>
                    <image>
                        <builder>paketobuildpacks/builder-noble-java-tiny</builder>
                        <env>
                            <BP_JVM_VERSION>23</BP_JVM_VERSION>
                        </env>
                    </image>
                    <jvmArguments>-agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ --enable-preview</jvmArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <buildArgs combine.children="append">
                        <buildArg>--enable-preview</buildArg>
                    </buildArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>23</source>
                    <target>23</target>
                    <compilerArgs>--enable-preview</compilerArgs>
                </configuration>

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

GraalVM 23 - VM 24.1.0 - aarch64

Operating System and Version

Reproducible with Mac Windowns and Linux

Build Command

mvn -Pnative spring-boot:build-image

Expected Behavior

I would have expected with all the enable preview used in the pom file (see above), the build would succeed.

Actual Behavior

Unfortunately, the build fails.

Steps to Reproduce

1 go to spring initializer to create a graalvm native project, as per Alina Yurenko's recommendations.

2 add a preview feature code, such as structured task scope.

3 run mvn -Pnative spring-boot:build-image

Additional Context

No response

Build Log Output and Error Messages

[INFO]     [creator]     For detailed information and explanations on the build output, visit:
[INFO]     [creator]     https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]     [1/8] Initializing...                                            (4.0s @ 0.27GB)
[INFO]     [creator]      Java version: 23.0.1+13, vendor version: Liberica-NIK-24.1.1-1
[INFO]     [creator]      Graal compiler: optimization level: 2, target machine: armv8-a
[INFO]     [creator]      C compiler: gcc (linux, aarch64, 13.2.0)
[INFO]     [creator]      Garbage collector: Serial GC (max heap size: 80% of RAM)
[INFO]     [creator]      2 user-specific feature(s):
[INFO]     [creator]      - com.oracle.svm.thirdparty.gson.GsonFeature
[INFO]     [creator]      - org.springframework.aot.nativex.feature.PreComputeFieldFeature
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]      3 experimental option(s) unlocked:
[INFO]     [creator]      - '-H:Name' (alternative API option(s): -o com.MyApplication; origin(s): command line)
[INFO]     [creator]      - '-H:ResourceConfigurationResources' (origin(s): 'META-INF/native-image/com.networknt/json-schema-validator/native-image.properties' in 'file:///workspace/BOOT-INF/lib/json-schema-validator-1.5.5.jar')
[INFO]     [creator]      - '-H:ReflectionConfigurationResources' (origin(s): 'META-INF/native-image/com.networknt/json-schema-validator/native-image.properties' in 'file:///workspace/BOOT-INF/lib/json-schema-validator-1.5.5.jar')
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]     Build resources:
[INFO]     [creator]      - 5.78GB of memory (75.6% of 7.65GB system memory, determined at start)
[INFO]     [creator]      - 12 thread(s) (100.0% of 12 available processor(s), determined at start)
[INFO]     [creator]     Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
[INFO]     [creator]     Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
[INFO]     [creator]     SLF4J(W): No SLF4J providers were found.
[INFO]     [creator]     SLF4J(W): Defaulting to no-operation (NOP) logger implementation
[INFO]     [creator]     SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
[INFO]     [creator]     [2/8] Performing analysis...  []                                (14.0s @ 1.42GB)
[INFO]     [creator]        17,593 reachable types   (80.6% of   21,822 total)
[INFO]     [creator]        21,332 reachable fields  (48.7% of   43,806 total)
[INFO]     [creator]        56,485 reachable methods (37.7% of  149,782 total)
[INFO]     [creator]         9,140 types, 1,551 fields, and 3,685 methods registered for reflection
[INFO]     [creator]     
[INFO]     [creator]     Error: java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/MyService (class file version 67.65535). Try running with '--enable-preview'
[INFO]     [creator]     Caused by: java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/MyService (class file version 67.65535). Try running with '--enable-preview'
[INFO]     [creator]     	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
[INFO]     [creator]     	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1026)
[INFO]     [creator]     	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
[INFO]     [creator]     	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageClassLoader.defineClass(NativeImageClassLoader.java:490)
[INFO]     [creator]     	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageClassLoader.findClassViaClassPath(NativeImageClassLoader.java:442)
[INFO]     [creator]     	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageClassLoader.loadClass(NativeImageClassLoader.java:629)
[INFO]     [creator]     	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:528)
[INFO]     [creator]     	at java.base/java.lang.Class.getDeclaredFields0(Native Method)
[INFO]     [creator]     	at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3545)
[INFO]     [creator]     	at java.base/java.lang.Class.getDeclaredFields(Class.java:2601)
[INFO]     [creator]     	at org.springframework.aot.nativex.feature.PreComputeFieldFeature.iterateFields(PreComputeFieldFeature.java:63)
[INFO]     [creator]     	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisElement$SubtypeReachableNotification.lambda$notifyCallback$0(AnalysisElement.java:174)
[INFO]     [creator]     	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
[INFO]     [creator]     	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:69)
[INFO]     [creator]     	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisElement.lambda$execute$2(AnalysisElement.java:220)
[INFO]     [creator]     	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:166)
[INFO]     [creator]     	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:152)
[INFO]     [creator]     	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1726)
[INFO]     [creator]     	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1717)
[INFO]     [creator]     	at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1641)
[INFO]     [creator]     	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
[INFO]     [creator]     	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1458)
[INFO]     [creator]     	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2034)
[INFO]     [creator]     	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:189)

@patpatpat123
Copy link
Author

enablepreviewissue.zip

@patpatpat123
Copy link
Author

minimal attached, please run

mvn -Pnative spring-boot:build-image

@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Feb 12, 2025
@patpatpat123
Copy link
Author

Hello @oubidar-Abderrahim ,

Thank you for taking a look into this.

If you need me to provide any other additional information, please feel free to let me know.

@oubidar-Abderrahim
Copy link
Member

Thank you, I was trying to reproduce the issue and running mvn -Pnative spring-boot:build-image but the build fails with

Exception in thread "main" java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/example/enablepreviewissue/DummyController (class file version 67.65535). Try running with '--enable-preview'
...
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.4.2:process-aot (process-aot) on project enablepreviewissue: Process terminated with exit code: 1

Is there a step missing in the reproducer?

@patpatpat123
Copy link
Author

Hello @oubidar-Abderrahim ,

Sincere apologies, a wrong copy paste on my end.

From the POM file, could you please replace this

(This is wrong)

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <compilerArguments>--enable-preview</compilerArguments>
                    <image>
                        <builder>paketobuildpacks/builder-noble-java-tiny</builder>
                        <env>
                            <BP_JVM_VERSION>23</BP_JVM_VERSION>
                        </env>
                    </image>
                    <jvmArguments>-agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ --enable-preview</jvmArguments>
                </configuration>
            </plugin>

With this?

(This is correct)

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>--enable-preview</jvmArguments>
                    <compilerArguments>--enable-preview</compilerArguments>
                    <image>
                        <builder>paketobuildpacks/builder-noble-java-tiny</builder>
                        <env>
                            <BP_JVM_VERSION>23</BP_JVM_VERSION>
                        </env>
                    </image>
                    <jvmArguments>-agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ --enable-preview</jvmArguments>
                </configuration>
            </plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants