JDK-7072895 : Generic inner class cannot access outer class members
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2011-07-29
  • Updated: 2012-03-20
  • Resolved: 2011-08-02
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Linux kitko-desktop 2.6.35-30-generic #54-Ubuntu SMP Tue Jun 7 18:40:23 UTC 2011 i686 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
public class Outer {
  private int iOuter;

  /** This is ok on both java6 and java7 */
  <T extends Outer> void mOuter(Inner<T> inner){
    System.out.println(inner.iInner);
  }

  static class Inner<T extends Outer> {
    private int iInner;

    /** Here we get compilation error on java 7 only */
    void mInner(T outer){
      System.out.println(outer.iOuter);
    }

  }
}

Sample program compiles ok on java6.
On java7 we get :

Outer.java:14: error: iOuter has private access in Outer
      System.out.println(outer.iOuter);
                              ^
1 error


REGRESSION.  Last worked in version 6u26

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Save the sample
-------------------------------------------------
public class Outer {
  private int iOuter;

  /** This is ok on both java6 and java7 */
  <T extends Outer> void mOuter(Inner<T> inner){
    System.out.println(inner.iInner);
  }

  static class Inner<T extends Outer> {
    private int iInner;

    /** Here we get compilation error on java 7 only */
    void mInner(T outer){
      System.out.println(outer.iOuter);
    }

  }
}
--------------------------------------------------

and try to compile on java7, u will get error

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should compile on java7
ACTUAL -
Does not compile

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Outer.java:14: error: iOuter has private access in Outer
      System.out.println(outer.iOuter);
                              ^
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Outer {
  private int iOuter;

  /** This is ok on both java6 and java7 */
  <T extends Outer> void mOuter(Inner<T> inner){
    System.out.println(inner.iInner);
  }

  static class Inner<T extends Outer> {
    private int iInner;

    /** Here we get compilation error on java 7 only */
    void mInner(T outer){
      System.out.println(outer.iOuter);
    }

  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use getters . But this is not acceptable

Comments
PUBLIC COMMENTS This is in the release notes for JDK 7: http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#source (Compiler No Longer Allows Access to Private Members of Type Variables)
02-08-2011