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

java.lang.AssertionError: Unexpected type tree: (ERROR) = (ERROR)

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      MacBook Pro M1 Max macOS 15.3.1 (24D70),
      openjdk version "23.0.2" 2025-01-21
      OpenJDK Runtime Environment Homebrew (build 23.0.2)
      OpenJDK 64-Bit Server VM Homebrew (build 23.0.2, mixed mode, sharing)

      Also reproducible on Coretto on Linux.

      A DESCRIPTION OF THE PROBLEM :
      Compiling (.java) source code with a syntactically invalid program causes javac to raise an AssertionError rather than failing gracefully. In one test case (Minimal.java), both javac and javax.tools.JavaCompiler fail. In another test case (Full.java), only javax.tools.JavaCompiler fails:

      // javac Minimal.java:
      An exception has occurred in the compiler (23.0.2). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      java.lang.AssertionError: Unexpected type tree: (ERROR) = (ERROR)
      at jdk.compiler/com.sun.tools.javac.tree.TreeInfo.typeIn(TreeInfo.java:1332)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JavacParser.java:5219)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseType(JavacParser.java:1044)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArgument(JavacParser.java:2400)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArguments(JavacParser.java:2365)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArguments(JavacParser.java:2434)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArgumentsOpt(JavacParser.java:2330)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term3(JavacParser.java:1677)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term2(JavacParser.java:1177)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term1(JavacParser.java:1148)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term(JavacParser.java:1104)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term(JavacParser.java:1084)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.unannotatedType(JavacParser.java:1069)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.unannotatedType(JavacParser.java:1065)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.topLevelMethodOrFieldDeclaration(JavacParser.java:4880)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:4084)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:653)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:630)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:690)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1041)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler$InitialFileParser.parse(JavaCompiler.java:1975)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1028)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:950)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)
      printing javac parameters to: /var/folders/yj/t6vpknfj35d1bmqhdf51bcfr0000gn/T/javac.20250303_120113.args

      // javax.tools.JavaCompiler Full.java
      An exception has occurred in the compiler (23.0.2). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      java.lang.AssertionError: Unexpected type tree: (ERROR) = 5
      at jdk.compiler/com.sun.tools.javac.tree.TreeInfo.typeIn(TreeInfo.java:1332)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JavacParser.java:5219)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseType(JavacParser.java:1044)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArgument(JavacParser.java:2400)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArguments(JavacParser.java:2365)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArguments(JavacParser.java:2434)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeArgumentsOpt(JavacParser.java:2330)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term3(JavacParser.java:1677)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term2(JavacParser.java:1177)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term1(JavacParser.java:1148)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term(JavacParser.java:1104)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term(JavacParser.java:1084)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.unannotatedType(JavacParser.java:1069)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.unannotatedType(JavacParser.java:1065)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseType(JavacParser.java:1041)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseType(JavacParser.java:1037)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.formalParameter(JavacParser.java:5280)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.formalParameters(JavacParser.java:5145)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.formalParameters(JavacParser.java:5137)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.methodDeclaratorRest(JavacParser.java:5005)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.constructorOrMethodOrFieldDeclaration(JavacParser.java:4812)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrRecordBodyDeclaration(JavacParser.java:4737)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classInterfaceOrRecordBody(JavacParser.java:4675)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classDeclaration(JavacParser.java:4363)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrRecordOrInterfaceOrEnumDeclaration(JavacParser.java:4307)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeDeclaration(JavacParser.java:4296)
      at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:4096)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:653)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:630)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:690)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1041)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler$InitialFileParser.parse(JavaCompiler.java:1975)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1028)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:950)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
      at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
      at nl.tudelft.cse1110.andy.Main.main(Main.java:28)
      at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
      at java.base/java.lang.reflect.Method.invoke(Method.java:580)
      at jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher.execute(SourceLauncher.java:268)
      at jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher.run(SourceLauncher.java:153)
      at jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher.main(SourceLauncher.java:78)

      REGRESSION : Last worked in version 23.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac Minimal.java --> this will fail with AssertionError

      Compiling BOTH Minimal.java AND Full.java will fail with AssertionError:

      package nl.tudelft.cse1110.andy;

      import javax.annotation.processing.AbstractProcessor;
      import javax.annotation.processing.RoundEnvironment;
      import javax.lang.model.element.TypeElement;
      import javax.tools.JavaCompiler;
      import javax.tools.JavaFileObject;
      import javax.tools.ToolProvider;
      import java.io.File;
      import java.util.List;
      import java.util.Set;

      public class Main {

          public static void main(String[] args) {

              List<File> files = List.of(new File("Full.java")); // NOTE: ALSO CRASHES FOR Minimal.java

              JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

              Iterable<? extends JavaFileObject> sources = compiler.getStandardFileManager(null, null, null).getJavaFileObjectsFromFiles(files);

              JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, null, null, sources);

              AbstractProcessor processor = new MyProcessor();
              task.setProcessors(List.of(processor));

              boolean compilationResult = task.call();
              System.out.println(compilationResult);
          }

          public static class MyProcessor extends AbstractProcessor {
              public boolean process(final Set< ? extends TypeElement> types, final RoundEnvironment environment) {
                  return true;
              }
          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect javac to not compile the code and give the user a syntax error for both test cases.

      I expect the call to javax.tools.JavaCompiler to return false, but not raise an AssertionError.

      I expect that both javac and javax.tools.JavaCompiler have the same outcome with the same test case.
      ACTUAL -
      javac raises an exception for Minimal.java (unexpected); and a user syntax error for Full.java (expected).

      The calls to javax.tools.JavaCompiler throws an AssertionError for both Minimal.java and Full.java, on top of returning false.

      javac and javax.tools.JavaCompiler exhibit the same behavior for Minimal.java. With Full.java, javac gives the user a syntax error but raises an exception with javax.tools.JavaCompiler (so they do not behave the same).

      ---------- BEGIN SOURCE ----------
      // Full.java
      package delft;

      class ListUtilsTest {

          void test(List<@AlphaChars <@StringLength(int value = 5)String> s){

          }


      }

      // Minimal.java
      B<@C<@D(e f=
      ---------- END SOURCE ----------

        1. Full.java
          0.1 kB
        2. Main.java
          1 kB
        3. Minimal.java
          0.0 kB

            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: