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

Compiler doesn't allow an inner class and a package of the same name to co-exist

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description

      Inner Classes in Java 1.1 whitepaper doesn't prohibit
      an inner class and a package of the same name to co-exist,
      since fully qualified name of an inner class differs from a
      package name.

      Nevertheless, compiler reports the following compile-time error,
      compiling the example_1 below:

      > jc A.java
      A.java:2: Class P.A. P.A not found in type declaration.
      class A {
            ^
      1 error
      >

      -------------------- Java code example_1 -----------------
      package P;
      class A {
            class P {}
      }
      ----------------------------------------------------------

      Apparently originating from the same source, another error
      does exist in 12beta2 Java compiler, discovered by Todd Turnidge:
      example_2 below makes compiler throw sun.tools.java.CompilerError:

      > jc A.java
      sun.tools.java.CompilerError: inner
              at sun.tools.java.ClassDefinition.resolveInnerClass(ClassDefinition.java:1497)
              at sun.tools.java.ClassDefinition.resolveName(ClassDefinition.java:1468)
              at sun.tools.java.Environment.resolveNames(Environment.java:242)
              at sun.tools.javac.SourceMember.resolveTypeStructure(SourceMember.java:306)
              at sun.tools.javac.SourceClass.resolveTypeStructure(SourceClass.java:1102)
              at sun.tools.javac.SourceClass.getSuperClass(SourceClass.java:597)
              at sun.tools.java.ClassDefinition.getInnerClass(ClassDefinition.java:869)
              at sun.tools.java.ClassDefinition.resolveInnerClass(ClassDefinition.java:1509)
              at sun.tools.java.ClassDefinition.resolveName(ClassDefinition.java:1468)
              at sun.tools.java.Environment.resolveNames(Environment.java:242)
              at sun.tools.javac.SourceMember.resolveTypeStructure(SourceMember.java:306)
              at sun.tools.javac.SourceClass.resolveTypeStructure(SourceClass.java:1102)
              at sun.tools.javac.SourceMember.resolveTypeStructure(SourceMember.java:302)
              at sun.tools.javac.SourceClass.resolveTypeStructure(SourceClass.java:1102)
              at sun.tools.javac.SourceClass.basicCheck(SourceClass.java:962)
              at sun.tools.java.ClassDeclaration.getClassDefinition(ClassDeclaration.java:122)
              at sun.tools.javac.Main.compile(Main.java:345)
              at sun.tools.javac.Main.main(Main.java:571)
      error: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
      1 error
      >

      -------------------- Java code example_2 -----------------
      package P;
      class A {
      class Q {
      class P {}
      }
      }
      ----------------------------------------------------------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wmaddoxsunw William Maddox (Inactive)
              Reporter:
              oulyankisunw Oleg Ulyankin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: