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

javac Analyzers should handle non-deferrable errors

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 25
    • 25
    • tools
    • None
    • b10

      Some errors reported by javac have the "NON_DEFERRABLE" flag, which means the error should not be stored in `DeferredDiagnosticHandler`, but rather should be reported immediately.

      This is particularly the case when e.g. entering the sources before annotation processing - the errors are not reported to the user immediately, as they may be resolved by the AP. Hence ordinary errors are stored in `DeferredDiagnosticHandler` and reported later if needed. Non-deferrable errors are not stored, but reported immediately, as those are typically serious errors that cannot be fixed by AP.

      javac also has an `Analyzer`, which looks for code simplifications by speculatively simplifying the code, and re-attributing it to see if it would still compile. It is using `DeferredDiagnosticHandler`, so that if any errors are found during the speculative attribution, the code simplification is rejected.

      But, if a non-deferrable error is reported during the speculative attribution, it is passed through `DeferredDiagnosticHandler` undetected, and the `Analyzer` may try to do further evaluations - which may crash the compiler.

      See the attached jtreg test. It fails with:
      ---
      An exception has occurred in the compiler (25-internal). 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: Analyzer error when processing: Utils.run(new Task<Param>(){
          
          () {
              super();
          }
          
          @Override
          public void run(Param parameter) throws Exception {
          }
      });:java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.getTypeArguments()" because "com.sun.tools.javac.util.List.get(int).type" is null
      jdk.compiler/com.sun.tools.javac.comp.Analyzer$DiamondInitializer.process(Analyzer.java:258)
      jdk.compiler/com.sun.tools.javac.comp.Analyzer$DiamondInitializer.process(Analyzer.java:228)
      jdk.compiler/com.sun.tools.javac.comp.Analyzer.doAnalysis(Analyzer.java:577)
      jdk.compiler/com.sun.tools.javac.comp.Analyzer$2.flush(Analyzer.java:547)
      jdk.compiler/com.sun.tools.javac.comp.Analyzer.flush(Analyzer.java:591)
      jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1427)
      jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1395)
      jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:983)
      jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
      jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
      jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
      toolbox.JavacTask.runAPI(JavacTask.java:420)
      toolbox.JavacTask.run(JavacTask.java:359)
      toolbox.AbstractTask.run(AbstractTask.java:102)
      toolbox.JavacTask.run(JavacTask.java:52)
      toolbox.JavacTask.run(JavacTask.java:321)
      Diamond.testUndefinedConstructorParam(Diamond.java:126)
      java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
      java.base/java.lang.reflect.Method.invoke(Method.java:565)
      toolbox.TestRunner.runTests(TestRunner.java:91)
      Diamond.runTests(Diamond.java:61)
      Diamond.main(Diamond.java:52)
      java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
      java.base/java.lang.reflect.Method.invoke(Method.java:565)
      com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
      java.base/java.lang.Thread.run(Thread.java:1447)
      at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
      at jdk.compiler/com.sun.tools.javac.comp.Analyzer.doAnalysis(Analyzer.java:579)
      at jdk.compiler/com.sun.tools.javac.comp.Analyzer$2.flush(Analyzer.java:547)
      at jdk.compiler/com.sun.tools.javac.comp.Analyzer.flush(Analyzer.java:591)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1427)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1395)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:983)
      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 toolbox.JavacTask.runAPI(JavacTask.java:420)
      at toolbox.JavacTask.run(JavacTask.java:359)
      at toolbox.AbstractTask.run(AbstractTask.java:102)
      at toolbox.JavacTask.run(JavacTask.java:52)
      at toolbox.JavacTask.run(JavacTask.java:321)
      at Diamond.testUndefinedConstructorParam(Diamond.java:126)
      at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
      at java.base/java.lang.reflect.Method.invoke(Method.java:565)
      at toolbox.TestRunner.runTests(TestRunner.java:91)
      at Diamond.runTests(Diamond.java:61)
      at Diamond.main(Diamond.java:52)
      at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
      at java.base/java.lang.reflect.Method.invoke(Method.java:565)
      at java.base/java.lang.Thread.run(Thread.java:1447)
      ---

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

              Created:
              Updated:
              Resolved: