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

NullPointerException for local interface with a nested subtype

XMLWordPrintable

    • 20
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      An exception occurs in the compiler when it encounters a nested interface that extends its enclosing interface, and the latter is local.

      Affected javac versions: 20.0.2, 21.0.1, 23.0.2

      Compiles OK with javac versions: 19.0.2, 17.0.8

      Compiling the attached source with javac 20.0.2 fails with:

      java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.util.List.nonEmpty()" because "l" is null
              at jdk.compiler/com.sun.tools.javac.comp.Lower.freevarDefs(Lower.java:1467)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.freevarDefs(Lower.java:1459)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2216)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:810)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2098)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2240)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:810)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2098)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3609)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1088)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2098)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2775)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2691)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2098)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2240)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:810)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2098)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2117)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:4210)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1625)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1440)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960)
              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)

      Equivalent stack traces are generated for other affected versions.


      REGRESSION : Last worked in version 19

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Define a local interface B.
      2. Define interface/class/enum/record C nested in B and extending/implementing B.
      3. Compile.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program compiles successfully.
      ACTUAL -
      Compilation fails.

      ---------- BEGIN SOURCE ----------
      public class A {

          void m() {
              interface B {
                  // Compilation error
                  interface C extends B {}

                  // OK
                  // class C implements B {}

                  // OK
                  // interface C {}
              }

              // OK
              // interface C extends B {}
          }

          // OK
          interface B {
              interface C extends B {}
          }

      }
      ---------- END SOURCE ----------

            kfarrell Kieran Farrell
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: