Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-4049

UnsupportedClassVersionError when running JDK14 code with --enable-preview

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 11.3
    • None

    Description

      I have installed NB 11.3 on Windows 10, with JDK 14 as its only Java platform.

      I created a simple Java with Ant project, and wrote code using "arrow case" labels in a switch block:

       

      static boolean isModifiable(char c) {
          boolean canModify = switch (c) {
              case 'ñ', 'Ñ' ->
                  false;
              default ->
                  true;
          };
          return canModify;
       }
      

       

      NetBeans detected that this was a JEP 354 preview feature, and set --enable-preview for compilation (Properties > Build > Compiling > Additional Compiler Options) and execution (Properties > Run > VM Options).

      The code compiled with no problems, but running it (Run > Run Project) resulted in this error:

       

      run:
      Error: LinkageError occurred while loading main class com.Diacritics java.lang.UnsupportedClassVersionError: com/Diacritics (class file version 57.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 58.65535
      C:\Users\johndoe\AppData\Local\NetBeans\Cache\11.3\executor-snippets\run.xml:111: The following error occurred while executing this line:
      C:\Users\johndoe\AppData\Local\NetBeans\Cache\11.3\executor-snippets\run.xml:68: Java returned: 1
      BUILD FAILED (total time: 0 seconds)
      

      When I build the project the message is logged 

      To run this application from the command line without Ant, try:
      java -jar "D:\NB113\Diacritics\dist\Diacritics.jar"

      If I run from the command line with JDK 14 on the PATH, using what NetBeans proposes (i.e. java jar "D:\NB113\Diacritics\dist\Diacritics.jar") I also get the linkage error described above. However, when I added the -enable-preview option to the command line call it works fine, as shown in this screen shot:

      This suggests that when running the project within NetBeans the VM Option --enable-preview is being ignored.

      There is no issue when creating a Java application using Java with Maven that contains the same code. This is only an issue for Java with Ant projects.

       

      Attachments

        1. nb113enablePreview.png
          43 kB
          Rick Hegarty

        Activity

          People

            Unassigned Unassigned
            skomisa Rick Hegarty
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: