JDK-8034924 : Incorrect inheritance of inaccessible static method
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-02-14
  • Updated: 2014-07-31
  • Resolved: 2014-03-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20 b09Fixed 9Fixed
Description
This code:

=== base/BaseImpl.java ===
package base;

public class BaseImpl {
  static void foo(Object o) {}
}
===

=== Test.java ===
class Impl extends base.BaseImpl {
  public void foo(Object o) {}
}

class MyImpl extends Impl {
  public void m(Object o) {
    foo(o);
  }
}
===

after compilation:
javac base/BaseImpl.java Test.java

fails with:
Test.java:7: error: no enclosing instance of type Impl is in scope
    foo(o);
    ^

reported by Liam Miller-Cushon at compiler-dev: http://mail.openjdk.java.net/pipermail/compiler-dev/2014-February/008511.html
Comments
Verified using regression test tools/javac/IncorrectInheritance/IncorrectInheritanceTest.java
31-07-2014

ILW=HML -> P2
10-03-2014

ILW classification: Impact = H (regression) Likelihood = M Workaround = L (in general user should be able to change the name of the methods involved) (HML) => P2
10-03-2014

Release team: Approved for deferral.
18-02-2014

8-defer-request justification: This is not a show-stopper for the release please defer it
14-02-2014

Alex's comments: MyImpl inherits the instance method foo(Object) from Impl, and foo(o) should invoke the inherited method. javac is recognizing that the type Impl is an important source of truth. The foo(Object) method in base.BaseImpl is irrelevant because, having package access, it's not inherited by Impl. - The compile-time error appears (incorrectly) whether the static method in base.BaseImpl is package access or private. But if the static method is public, then everything works fine: Impl.foo(Object) attempts to override base.BaseImpl.foo(Object), and a compile-time error occurs because an instance method cannot override a static method. - In MyImpl.m, if you replace foo(o) with this.foo(o), then the program compiles correctly.
14-02-2014