[PATCH] 8071433: private static method in outer class shadowed by inherited public method
bsrbnd
bsrbnd at gmail.com
Thu May 14 10:36:47 UTC 2015
Hi,
Thanks for your answer.
You're right.
Referring to JLS 15.12.1, method shadow(boolean) should be called from
class FailImpl the following way:
public void a() {
StaticFail.shadow(false);
((StaticFail)this).shadow(false);
super.shadow(false);
}
Issue 8071433 should be closed?
Regards,
bsrbnd
2015-05-11 16:47 GMT+02:00 Maurizio Cimadamore <maurizio.cimadamore at oracle.com>:
> Is this even an issue?
>
> See JLS 15.12.1:
>
> "If the form is MethodName, that is, just an Identifier, then:
>
> If the Identifier appears in the scope of a visible method declaration with
> that name (§6.3, §6.4.1), then:
>
> If there is an enclosing type declaration of which that method is a
> member, let T be the innermost such type declaration. The class or interface
> to search is T.
>
> This search policy is called the "comb rule". It effectively looks for
> methods in a nested class's superclass hierarchy before looking for methods
> in an enclosing class and its superclass hierarchy. See §6.5.7.1 for an
> example."
>
> Here we have that FailImpl has an inherited member 'shadow()' - which means
> FailImpl is the class to search. This will give you the type error.
>
> Maurizio
>
>
> On 11/05/15 14:52, bsrbnd wrote:
>
> Hi,
>
> 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
> inherited).
>
> 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() {
> shadow(false);
> }
> }
>
> 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
> inapplicable.
> 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
> b/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.
>
> Regards,
>
> bsrbnd
>
>
More information about the compiler-dev
mailing list