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

null qualifying inner instance creation should be error.

    XMLWordPrintable

Details

    • hopper
    • generic
    • generic
    • Verified

    Description



      Name: boT120536 Date: 01/22/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


      According to JLS 15.9.1, sub-bullet 2 of second paragraph, "It is a compile-time
      error if Identifier is not the simple name of an accessible non-abstract inner
      class T that is a member of the compile-time type of the Primary." Then, in
      4.1, it reads "There is also a special null type, the type of the expression
      null." Since the null literal is its own type, and not a reference type, and
      since it has no inner classes, this code should fail to compile:

      class Outer {
          class Inner{}
          Object o = null.new Inner();
          public static void main(String[] args) {
              System.out.println(new Outer().o);
          }
      }

      But javac 1.3 compiles it, with no second thoughts. Even weirder, when I
      execute, I would expect a null-pointer exception according to 15.9.4, but
      instead I get some nice output confirming an inner class instance was created.

      So, I next tried this modification:

      class Outer {
          class Inner {}
          Object o = null.new Inner(){};
      }

      Lo and behold, it only gets more interesting:

      An exception has occurred in the compiler (1.3.0). Please file a bug at the Java
       Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi). Include your
       program and the following diagnostic in your report. Thank you.
      java.lang.InternalError: unexpected type: <null>
              at com.sun.tools.javac.v8.tree.TreeMaker.Type(TreeMaker.java:399)
              at com.sun.tools.javac.v8.tree.TreeMaker.VarDef(TreeMaker.java:437)
              at com.sun.tools.javac.v8.tree.TreeMaker.Param(TreeMaker.java:463)
              at com.sun.tools.javac.v8.tree.TreeMaker.Params(TreeMaker.java:474)
              at com.sun.tools.javac.v8.comp.Enter.DefaultConstructor(Enter.java:170)
              at com.sun.tools.javac.v8.comp.Enter$CompleteEnter.complete(Enter.java:8
      34)
              at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:366)
              at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:341)
              at com.sun.tools.javac.v8.tree.Tree$ClassDef.visit(Tree.java:402)
              at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:234)
              at com.sun.tools.javac.v8.comp.Attr.attribStat(Attr.java:276)
              at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:871)
              at com.sun.tools.javac.v8.tree.Tree$NewClass.visit(Tree.java:810)
              at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:234)
              at com.sun.tools.javac.v8.comp.Attr.attribExpr(Attr.java:254)
              at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:402)
              at com.sun.tools.javac.v8.tree.Tree$VarDef.visit(Tree.java:470)
              at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:234)
              at com.sun.tools.javac.v8.comp.Attr.attribStat(Attr.java:276)
              at com.sun.tools.javac.v8.comp.Attr.attribClass(Attr.java:1415)
              at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:378)
              at com.sun.tools.javac.v8.Main.compile(Main.java:247)
              at com.sun.tools.javac.Main.main(Main.java:16)
      (Review ID: 115114)
      ======================================================================

      Attachments

        Activity

          People

            gafter Neal Gafter
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: