[ https://issues.apache.org/jira/browse/MCOMPILER-546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17769303#comment-17769303 ]
Tamas Cservenak edited comment on MCOMPILER-546 at 9/26/23 6:15 PM: -------------------------------------------------------------------- [~vlad.galuska] , this seems JDK bug. Try without maven, just to compile the class manually as you did but add "debug" flag: {noformat} javac --enable-preview --release 21 -g org/example/Main.java {noformat} And resulting class file will behave same as Maven compiled one. Reason: {{-g}} is by default appended to javac flags by m-compiler-p. OR, disable debug: {noformat} diff --git a/pom.xml b/pom.xml index 5c8ee26..b15c4b4 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ <configuration> <source>21</source> <target>21</target> + <debug>false</debug> <compilerArgs> <arg>--enable-preview</arg> </compilerArgs> @@ -44,4 +45,4 @@ </build> -</project> \ No newline at end of file +</project> {noformat} Still, this seems JDK bug, please report it. was (Author: cstamas): Vlad, this seems JDK bug. Try without maven, just to compile the class manually as you did but add "debug" flag: {noformat} javac --enable-preview --release 21 -g org/example/Main.java {noformat} And resulting class file will behave same as Maven compiled one. Reason: {{-g}} is by default appended to javac flags by m-compiler-p. OR, disable debug: {noformat} diff --git a/pom.xml b/pom.xml index 5c8ee26..b15c4b4 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ <configuration> <source>21</source> <target>21</target> + <debug>false</debug> <compilerArgs> <arg>--enable-preview</arg> </compilerArgs> @@ -44,4 +45,4 @@ </build> -</project> \ No newline at end of file +</project> {noformat} Still, this seems JDK bug, please report it. > Maven compiling fails when using JEP 443 > ---------------------------------------- > > Key: MCOMPILER-546 > URL: https://issues.apache.org/jira/browse/MCOMPILER-546 > Project: Maven Compiler Plugin > Issue Type: Bug > Affects Versions: 3.11.0 > Environment: Both MacOS and Windows. > Maven 3.9.4 > Maven Compiler 3.11 > Java 21 Preview > Reporter: Vlad Galuska > Priority: Major > Attachments: mvn-compile-1.log, pom.xml > > > I'm trying to test out the preview feature described in JEP 443: Unnamed > patterns and variables [https://openjdk.org/jeps/443] . I have the following: > {code:java} > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-compiler-plugin</artifactId> > <configuration> > <source>21</source> > <target>21</target> > <compilerArgs> > <arg>--enable-preview</arg> > </compilerArgs> > </configuration> > </plugin> {code} > I then run `mvn -X compile`, the result of which has been attached as > mvn-compile.log. > The target just contains the Main.class file and the `createdFiles.lst` with: > `org/example/Main.class` and `inputFiles.lst` with: > `/Users/vlad.galuska/IdeaProjects/preview/Java21Preview/src/main/java/org/example/Main.java` > {*}Note{*}: The picture is from IntelIJ but all the commands have been run > from the command line. > When running the generated .class file: > `cd target/classes ` > `java --enable-preview org.example.Main` > I get the following message: > ``` > Error: LinkageError occurred while loading main class org.example.Main > java.lang.ClassFormatError: Illegal field name "" in class > org/example/Main > ``` > This only happens when using the maven compiler plugin as when compiling > manually from the command line: > `javac --enable-preview --release 21 org/example/Main.java ` > `java --enable-preview org.example.Main ` > I get the intended result: > ``` > Hello, World! > Hello, World! > Hello, World! > ``` > The same behavior has been recorded on Windows. I've also tried this with the > amazon coretto version of java 21, OpenJDK Java 21 GA release and OpenJDK > java 21.ea.35-open. > Maven is also a clean install of 3.9.4, but was reproduced with a 3.8 I had > installed previously. > Here's also a repository where I have uploaded the code base for this bug > report: > [https://github.com/VladGaluska/jdk21-preview-bug] > -- This message was sent by Atlassian Jira (v8.20.10#820010)