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 {}
}
}
----------------------------------------------------------
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 {}
}
}
----------------------------------------------------------
- relates to
-
JDK-4053302 compilation error with 1.1 compiler, 1.0.2 works fine.
- Closed
-
JDK-4093882 Compiler allows a top-level class and a package of the same name to co-exist
- Closed