Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8327153

Compilation on Java 21 results in different error count as compared to Java 11 and 8

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 18.04.6 LTS

      A DESCRIPTION OF THE PROBLEM :
      When I run the Test.java file using hotspot-jdk-21.0.2, there are illegal strings in the java file and three errors occurred in hotspot-jdk-21.0.2. Immediately after I used hotspot-jdk-11.0.15 and hotspot-jdk8u352 to run the file, four errors occurred. I think four mistakes are more reasonable.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      cmd:hotspot-jdk-21.0.2/build/linux-x86_64-server-fastdebug/jdk/bin/javac Test.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected Result:
      [FOLDER]/openjdk/hotspot-jdk-11.0.15/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java Test.java
      Test.java:5: error: illegal escape character
          static String fParam1Param1Param1 = "i+eq.$s\ "Pt";
                                                       ^
      Test.java:5: error: ';' expected
          static String fParam1Param1Param1 = "i+eq.$s\ "Pt";
                                                         ^
      Test.java:5: error: unclosed string literal
          static String fParam1Param1Param1 = "i+eq.$s\ "Pt";
                                                           ^
      Test.java:33: error: class, interface, or enum expected
      }
      ^
      4 errors
      error: compilation failed
      ACTUAL -
      [FOLDER]/openjdk/hotspot-jdk-21.0.2/build/linux-x86_64-server-fastdebug/jdk/bin/javac Test.java
      Test.java:5: error: illegal escape character
          static String fParam1Param1Param1 = "i+eq.$s\ "Pt";
                                                       ^
      Test.java:5: error: unclosed string literal
          static String fParam1Param1Param1 = "i+eq.$s\ "Pt";
                                                           ^
      Test.java:33: error: class, interface, enum, or record expected
      }
      ^
      3 errors

      ---------- BEGIN SOURCE ----------
      import java.io.*;

      public class Test {
          static String fParam1Param1Param1 = "i+eq.$s\ "Pt";
          static File fParam1Param1 = new File(fParam1Param1Param1);
          static String fParam1Param2 = ",q<f:|06Gz";
          static File fParam1 = new File(fParam1Param1, fParam1Param2);
          static String fParam2 = "_=+dS!{./C";
          static File f = new File(fParam1, fParam2);

          String read(File f) throws IOException {
              int enda = 0;
              int starta = 5;
              StringBuilder sb = new StringBuilder();
              BufferedReader in = new BufferedReader(new FileReader(f));
              try {
                  String line;
                  while ((line = in.readLine()) != null) {
                      sb.append(line);
                      sb.delete(starta, enda);
                  }
              } finally {
                  in.close();
              }
              return sb.toString();
          }

          public static void main(String[] args) throws Exception {
              System.out.println(new Test().read(f));
          }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: