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

ArrayIndexOutOfBoundsException with text blocks in javac when using -Xlint

XMLWordPrintable

    • b27
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "13" 2019-09-17
      OpenJDK Runtime Environment (build 13+33)
      OpenJDK 64-Bit Server VM (build 13+33, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      When I compile the following java program
      ```
      class C {

          void x() {
              String s = """

      """;
          }
      }
      ```
      with the following command:
      ```
      javac --release 13 --enable-preview -Xlint X.java
      ```

      then this exception is thrown by javac:
      java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 0
              at jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer$TextBlockSupport.checkWhitespace(JavaTokenizer.java:348)
              at jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.readToken(JavaTokenizer.java:1033)
              at jdk.compiler/com.sun.tools.javac.parser.Scanner.nextToken(Scanner.java:115)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.nextToken(JavacParser.java:263)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.variableDeclaratorRest(JavacParser.java:3249)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.variableDeclaratorsRest(JavacParser.java:3220)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.variableDeclarators(JavacParser.java:3202)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.localVariableDeclarations(JavacParser.java:2643)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.blockStatement(JavacParser.java:2630)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.blockStatements(JavacParser.java:2484)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.block(JavacParser.java:2454)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.block(JavacParser.java:2468)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.methodDeclaratorRest(JavacParser.java:4012)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceBodyDeclaration(JavacParser.java:3947)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceBody(JavacParser.java:3848)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classDeclaration(JavacParser.java:3687)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrEnumDeclaration(JavacParser.java:3641)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeDeclaration(JavacParser.java:3630)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:3474)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:639)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:676)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1031)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1018)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:938)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:318)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the following java program
      ```
      class C {

          void x() {
              String s = """

      """;
          }
      }
      ```
      with the following command:
      ```
      javac --release 13 --enable-preview -Xlint X.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Succesful compilation.
      ACTUAL -
      An exception is thrown by javac:

      java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 0
              at jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer$TextBlockSupport.checkWhitespace(JavaTokenizer.java:348)
              at jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.readToken(JavaTokenizer.java:1033)
              at jdk.compiler/com.sun.tools.javac.parser.Scanner.nextToken(Scanner.java:115)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.nextToken(JavacParser.java:263)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.variableDeclaratorRest(JavacParser.java:3249)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.variableDeclaratorsRest(JavacParser.java:3220)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.variableDeclarators(JavacParser.java:3202)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.localVariableDeclarations(JavacParser.java:2643)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.blockStatement(JavacParser.java:2630)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.blockStatements(JavacParser.java:2484)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.block(JavacParser.java:2454)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.block(JavacParser.java:2468)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.methodDeclaratorRest(JavacParser.java:4012)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceBodyDeclaration(JavacParser.java:3947)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceBody(JavacParser.java:3848)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classDeclaration(JavacParser.java:3687)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrEnumDeclaration(JavacParser.java:3641)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeDeclaration(JavacParser.java:3630)
              at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:3474)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:639)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:676)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1031)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1018)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:938)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:318)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


      ---------- BEGIN SOURCE ----------

      class C {

          void x() {
              String s = """

      """;
          }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      remove the -Xlint option from the command

      FREQUENCY : always


            jlaskey Jim Laskey
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: