Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8142829 | emb-9 | Srikanth Adayapalam | P4 | Resolved | Fixed | team |
FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux Mint (Rebecca, 3.13.0-37-generic #64-Ubuntu SMP)
Mac OS X Yosemite
A DESCRIPTION OF THE PROBLEM :
Attempting to create a method reference super::Identifier fails when:
- Superclass is declared in a different package
- Method being referenced is declared protected in Superclass
This compiles properly in Eclipse, but fails in Oracle JDK 8 javac.
According to JLS 6.6.2, a protected method can be accessed in the body of a subclass, except in the cases mentioned in the bullet points. super::identifier matches none of the cases, "super" not being an ExpressionName, a Primary expression, nor a ReferenceType.
Therefore such access should be allowable, exactly as the invocation super.x() would be.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create the two classes in the test case below, and compile them with
javac package1/Parent.java package2/Child2.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation should succeed.
ACTUAL -
Compilation error:
ERROR MESSAGES/STACK TRACES THAT OCCUR :
package2/Child2.java:8: error: incompatible types: invalid method reference
Runnable r = super::protectedMethod;
^
protectedMethod() has protected access in Parent
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package package1;
public class Parent {
protected void protectedMethod() {
System.out.println("Parent's protected method");
}
}
package package2;
public class Child extends package1.Parent {
public void protectedMethod() {
System.out.println( "In Child's protected method, calling Parent's" );
Runnable r = super::protectedMethod;
r.run();
}
public static void main(String[] args) {
Child child = new Child();
child.protectedMethod();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Compiling with eclipse
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux Mint (Rebecca, 3.13.0-37-generic #64-Ubuntu SMP)
Mac OS X Yosemite
A DESCRIPTION OF THE PROBLEM :
Attempting to create a method reference super::Identifier fails when:
- Superclass is declared in a different package
- Method being referenced is declared protected in Superclass
This compiles properly in Eclipse, but fails in Oracle JDK 8 javac.
According to JLS 6.6.2, a protected method can be accessed in the body of a subclass, except in the cases mentioned in the bullet points. super::identifier matches none of the cases, "super" not being an ExpressionName, a Primary expression, nor a ReferenceType.
Therefore such access should be allowable, exactly as the invocation super.x() would be.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create the two classes in the test case below, and compile them with
javac package1/Parent.java package2/Child2.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation should succeed.
ACTUAL -
Compilation error:
ERROR MESSAGES/STACK TRACES THAT OCCUR :
package2/Child2.java:8: error: incompatible types: invalid method reference
Runnable r = super::protectedMethod;
^
protectedMethod() has protected access in Parent
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package package1;
public class Parent {
protected void protectedMethod() {
System.out.println("Parent's protected method");
}
}
package package2;
public class Child extends package1.Parent {
public void protectedMethod() {
System.out.println( "In Child's protected method, calling Parent's" );
Runnable r = super::protectedMethod;
r.run();
}
public static void main(String[] args) {
Child child = new Child();
child.protectedMethod();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Compiling with eclipse
- backported by
-
JDK-8142829 Can't use super::x method reference when x is protected
-
- Resolved
-