JDK-8013845 : Private field invisible in generics
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7u11
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2013-03-20
  • Updated: 2014-11-17
  • Resolved: 2013-05-16
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_11 " 
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux hostname 3.6.11-5.fc17.x86_64 #1 SMP Tue Jan 8 21:40:51 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Following class does not compile complaining about i being private:

class Test {
    private int i;

    <T extends Test> void set(T x) {
        x.i = 20;
    }
}

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile following class:

class Test {
    private int i;

    <T extends Test> void set(T x) {
        x.i = 20;
    }
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Code compiles
ACTUAL -
Test.java:5: error: i has private access in Test
        x.i = 20;


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class Test {
    private int i;

    <T extends Test> void set(T x) {
        x.i = 20;
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Introduction of extra variable of base type and using that one to access private fields:

class Test {
    private int i;

    <T extends Test> void set(T x) {
        Test y = x;
        y.i = 20;
    }
}
Comments
Closing as duplicate of JDK-7022052.
16-05-2013