[PATCH] 8071433: private static method in outer class shadowed by inherited public method

bsrbnd bsrbnd at gmail.com
Mon May 11 13:52:46 UTC 2015


As described in case 8071433, the following code doesn't compile
because public method shadow() inherited from StaticFail hides private
static method shadow(boolean) defined in the same class (but not

public class StaticFail {
    private static void shadow(boolean b) {System.out.println(b);}
    public void shadow() {}

    public static class FailImpl extends StaticFail {
        public void a() {

    public static void main(String[] args) {
        new FailImpl().a();

It should be possible to correct the problem by keeping on searching
in outer class if method shadow() is found in class FailImpl but
The following patch for the jdk9 shows a possible solution:

diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
@@ -1822,7 +1822,8 @@
             Symbol sym = findMethod(
                 env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
                 allowBoxing, useVarargs);
-            if (sym.exists()) {
+            // Keep on searching in outer environment if symbol is
found but inapplicable.
+            if (sym.exists() && !(sym instanceof
Resolve.InapplicableSymbolError)) {
                 if (staticOnly &&
                     sym.kind == MTH &&
                     sym.owner.kind == TYP &&

I hope this could help.



More information about the compiler-dev mailing list