United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6660289 declared bound in inner class referring a type variable of the outer class
JDK-6660289 : declared bound in inner class referring a type variable of the outer class

Details
Type:
Bug
Submit Date:
2008-02-07
Status:
Closed
Updated Date:
2011-05-18
Project Name:
JDK
Resolved Date:
2011-05-18
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Relates:
Relates:

Sub Tasks

Description
Description:
Compiler crashes with an NPE for the following code:

<code>
class Outer<T extends Outer.Inner>{

     class Inner<S extends T>{

    }
}
</code>
Compilation result is :
<output>

An exception has occurred in the compiler (1.7.0-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.NullPointerException
        at com.sun.tools.javac.code.Types.getBounds(Types.java:1802)
        at com.sun.tools.javac.comp.Check.checkNonCyclic1(Check.java:1486)
        at com.sun.tools.javac.comp.Check.checkNonCyclic1(Check.java:1487)
        at com.sun.tools.javac.comp.Check.checkNonCyclic(Check.java:1474)
        at com.sun.tools.javac.comp.Attr.attribTypeVariables(Attr.java:469)
        at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:904)
        at com.sun.tools.javac.code.Symbol.complete(Symbol.java:400)
        at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:777)
        at com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:719)
        at com.sun.tools.javac.comp.Resolve.isAccessible(Resolve.java:195)
        at com.sun.tools.javac.comp.Resolve.findMemberType(Resolve.java:883)
        at com.sun.tools.javac.comp.Resolve.findIdentInType(Resolve.java:1049)
        at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:1988)
        at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1880)
        at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1651)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:372)
        at com.sun.tools.javac.comp.Attr.attribType(Attr.java:402)
        at com.sun.tools.javac.comp.Attr.attribTypeVariables(Attr.java:458)
        at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:904)
        at com.sun.tools.javac.code.Symbol.complete(Symbol.java:400)
        at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:777)
        at com.sun.tools.javac.comp.Enter.complete(Enter.java:465)
        at com.sun.tools.javac.comp.Enter.main(Enter.java:443)
        at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:833)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:741)
        at com.sun.tools.javac.main.Main.compile(Main.java:386)
        at com.sun.tools.javac.main.Main.compile(Main.java:312)
        at com.sun.tools.javac.main.Main.compile(Main.java:303)
        at com.sun.tools.javac.Main.compile(Main.java:82)
        at com.sun.tools.javac.Main.main(Main.java:67)

</output>
<version>
/net/sqindia/export/disk09/jdk/7/latest/binaries/solsparc/bin/java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b24)
Java HotSpot(TM) Client VM (build 12.0-b01, mixed mode)


uname -a
SunOS hrajan 5.10 Generic sun4u sparc SUNW,Sun-Blade-100

                                    

Comments
SUGGESTED FIX

http://sa.sfbay.sun.com/projects/langtools_data/7/6660289/
                                     
2008-02-15
EVALUATION

This problem is due to the order in which javac perform attribution of type-variable bounds wrt class attribution. 

1) Attribution of class Outer<T extends Outer.Inner>
1a) Attribution of Outer triggers attribution of Outer's type variable
2) Attribution of Outer.T
2a) Attribution of Outer.T triggers attribution of its declared bound
3) Attribution of class Outer.Inner<S extends T>
3a) Attribution of Outer.Inner triggers attribution of Outer.Inner's type variable
4) Attribution of Outer.Inner<S>
4a) Attribution of Outer.Inner.S triggers attribution of its declared bound
5) Attribution of Outer.T - this does nothing but returning the type of T; as you can see, at this stage T's bound has not been set yet on the object representing the type of T.

At a later point, for each attributed type variable, javac performs a check to ensure that the bound of a given type variable does not introduce cyclic inheritance. But we have seen that no bound is set for Outer.T; for this is the reason javac crashes with a NPE when trying to detect a cycle in the inheritance tree induced by the declared bound of Outer.Inner.S.

The solution is to postpone the acyclicity checking after all the type-variable bounds have been attributed. Proper bound types will be set on their corresponding TypeVar objects as a side-effect of the whole attribution process.
                                     
2008-02-15



Hardware and Software, Engineered to Work Together