United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7022052 Invalid compiler error on private method and generics
JDK-7022052 : Invalid compiler error on private method and generics

Details
Type:
Bug
Submit Date:
2011-02-24
Status:
Closed
Updated Date:
2013-05-16
Project Name:
JDK
Resolved Date:
2011-03-03
Component:
tools
OS:
linux_ubuntu,linux,windows_xp
Sub-Component:
javac
CPU:
x86
Priority:
P4
Resolution:
Not an Issue
Affected Versions:
7
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b130)
Java HotSpot(TM) Server VM (build 21.0-b02, mixed mode)


A DESCRIPTION OF THE PROBLEM :
Existing code compiles fine in Java 6, doesn't compile in Java 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the attached code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile correctly
ACTUAL -
The code doesn't compile

ERROR MESSAGES/STACK TRACES THAT OCCUR :
privateMethod() has private access in JavacBug

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package bugs;

public class JavacBug
{
	public static <T extends JavacBug> void doIt (T t)
	{
		t.privateMethod ();
	}

	private void privateMethod () {}
}

---------- END SOURCE ----------

                                    

Comments
EVALUATION

The submitted program is not correct as per JLS 3rd. In short, you cannot access a private member of a type variable, as there is no static guarantee that the type-variable will be instantiated with a type in which the member will be inherited.

Below is reported the relevant JLS text:

JLS 4.4 (Type-Variables)

"The members of a type variable X with bound T & I1 ... In are the members of the intersection type (??4.9) T & I1 ... In appearing at the point where the type variable is declared."

JLS 4.9 (Intersection types)

"The members of an intersection type T1 & ... & Tn are determined as follows:
   *) For each Ti, 1in, let Ci be the most specific class or array type such that Ti <: Ci         Then there must be some Tk <: Ck such that Ck <: Ci for any i, 1in, or a compile-time        error occurs.
   *) For 1jn, if Tj is a type variable, then let ITj be an interface whose members are the        same as the **public** members of Tj; otherwise, if Tj is an interface, then let ITj         be Tj.
Then the intersection type has the same members as a class type (??8) with an empty body, direct superclass Ck and direct superinterfaces IT1 , ..., ITn, declared in the same package in which the intersection type appears."

It follows that an intersection type cannot have private members - this implies that type-variables also cannot have private members.
                                     
2011-03-03



Hardware and Software, Engineered to Work Together