implementation inconsistency with scope rules for Java generic types

Maurizio Cimadamore Maurizio.Cimadamore at Sun.COM
Wed Jun 18 10:54:00 PDT 2008

Hi Nick,
this is definitively an interesting question; if your example might look 
like a straight javac bug at first, it' less clear whether it should be 
considered as such when Subclass and NestedSubclass live in completely 
unrelated packages; I think that one in principle could exploit an 
eventual vulnerability (as the one you described for Eclipse) for 
acquiring access to members of a private type that otherwise cannot be 

In this particular case however, since the class referencing the private 
type is the class in which that type is defined, I don't think that an 
error should be raised - so this is indeed a javac bug.

Alex do you have any JLS paragraph handy to support this?

Nick Radov wrote:
> I've run across an interesting inconsistency between javac and the 
> Java compiler built in to the Eclipse 3.3.2 IDE. Try compiling this 
> piece of code.
> public class X<T> {
> }
> class Subclass extends X<Subclass.NestedSubclass> {
> @SuppressWarnings("unchecked")
> private final class NestedSubclass extends X {
> }
> }
> The javac compiler reports one error because the generic type 
> parameter of the Subclass class has private access, but Eclipse 
> reports no errors. I had reported this as an Eclipse bug, but one of 
> the Eclipse team thinks it may be a javac bug. You can see the Eclipse 
> bug report here: <>.
> Does anyone know for sure which is correct? As far as I can tell the 
> JLS doesn't explicitly state whether this is allowed, although it may 
> be implicit in the scope rules.
> *Nick Radov | Director, Research & Development | Axolotl Corp*
> <>, d: 408.920.0800 x116, f: 
> 408.920.0880
> 160 West Santa Clara St., Suite 1000, San Jose, CA, 95113
> /The information contained in this e-mail transmission may contain 
> confidential information. It is intended for the use of the addressee. 
> If you are not the intended recipient, any disclosure, copying, or 
> distribution of this information is strictly prohibited. If you 
> receive this message in error, please inform the sender immediately 
> and remove any record of this message./ 

More information about the compiler-dev mailing list