|
Quick Lists
|
|
Bug ID:
|
6660289
|
|
Votes
|
0
|
|
Synopsis
|
declared bound in inner class referring a type variable of the outer class
|
|
Category
|
java:compiler
|
|
Reported Against
|
|
|
Release Fixed
|
7(b25)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
2-High
|
|
Related Bugs
|
6677785
|
|
Submit Date
|
07-FEB-2008
|
|
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
Posted Date : 2008-02-07 07:36:52.0
|
|
Work Around
|
N/A
|
|
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.
Posted Date : 2008-02-15 16:01:43.0
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |