Summary
javac is producing suspicious results for code like (note toString is a mirror of a java.lang.Object method, the suspicious results only happen for methods that are mirror methods from java.lang.Object):
interface I {
public String toString();
public String test();
}
interface J extends I {}
The suspicious results are twofold:
Trees.isAccessible(..., I.toString, J)(i.e. accessibility check forI.toStringas a member ofJ, in some scope/context) returns false. ButI.toStringis an inherited member ofJand should be accessible under normal circumstances.- invocations like
J j = null; j.toString();will be attributed as referring tojava.lang.Object.toString, rather than toI.toString(J.toStringin classfile). This is observable either through theTrees.getElementAPI, or in the classfile
In both cases, this is different from behavior where one would use test instead of toString.
Problem
As seen in the Summary section, javac is producing some suspicious results. A significant contributing factor is that javac's internal model uses java.lang.Object as the supertype of interface types.
Solution
The proposal is for javac's behavior w.r.t. methods mirroring java.lang.Object methods and superinterface methods to be consistent.
Specification
The proposal is that, in the above example:
Trees.isAccessible(..., I.toString, J)will return true- invocations of
java.lang.Objectmethods on interfaces in the classfile will useinvokeinterfacereferring to the interface, which is consistent with JLS 9.2. This will be done regardless of whether the interface declares the method explicitly or not.
- csr of
-
JDK-8272564 Incorrect attribution of method invocations of Object methods on interfaces
-
- Resolved
-