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

javac crashes on re-compilation of inner class

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11, 17, 18
    • Fix Version/s: tbd
    • Component/s: tools
    • Labels:

      Description

      (synopsis is provisional)

      Submitting on behalf of Marian Koncek. Reproduces on JDK 17, have not tested other versions. Consider this weird example, where we compile the class with inner class, then decompile the inner class, and try to compile it back. The second javac invocation crashes.

      $ cat > Main.java <<"EOF"
      public class Main {
        int field = 0;
       
        public class A {
          void f() {
            ++field;
          }
        }
       
        public void f() {
          new A().f();
        }
       
        public static void main(String[] args) throws Exception {
          while (true) {
            new Main().f();
            Thread.sleep(500);
          }
        }
      }
      EOF
       
      # Happens at least on javac 11 and javac 17
      $ javac Main.java
       
      # This is the result of decompilation
      $ cat > Main\$A.java <<"EOF"
      public class Main$A {
        final Main this$0;

        public Main$A(final Main this$0) {
          this.this$0 = this$0;
        }
       
        void f() {
          final Main this$0 = this.this$0;
          ++this$0.field;
        }
      }
      EOF
       
      $ javac Main\$A.java
      An exception has occurred in the compiler (17.0.1-testing). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://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.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.getDeclarationAttributes()" because "sym" is null
      at jdk.compiler/com.sun.tools.javac.code.Lint.augment(Lint.java:75)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitVarDef(Flow.java:594)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1027)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:444)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStat(Flow.java:504)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStats(Flow.java:512)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitBlock(Flow.java:604)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:444)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStat(Flow.java:504)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitMethodDef(Flow.java:568)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:444)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitClassDef(Flow.java:548)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:444)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:945)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:937)
      at jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:220)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1377)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1351)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

      Notably, invoking with Main.java in javac "passes" with proper compilation error:

      $ javac Main.java Main\$A.java
      Main$A.java:1: error: class Main$A is public, should be declared in a file named Main$A.java
      public class Main$A {
             ^
      1 error

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: