diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 1d558d47ae1..a1a1fe67644 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -1569,9 +1569,10 @@ void analyzeSymbol(JCTree tree) { * @param sym The symbol */ private boolean isEarlyReference(Env env, JCTree tree, Symbol sym) { - if ((sym.flags() & STATIC) == 0 && - (sym.kind == VAR || sym.kind == MTH) && - sym.isMemberOf(env.enclClass.sym, types)) { + if ((sym.kind == VAR || sym.kind == MTH) && + sym.isMemberOf(env.enclClass.sym, types) && + ((sym.flags() & STATIC) == 0 || + (sym.kind == MTH && tree instanceof JCFieldAccess))) { // Allow "Foo.this.x" when "Foo" is (also) an outer class, as this refers to the outer instance if (tree instanceof JCFieldAccess fa) { return TreeInfo.isExplicitThisReference(types, (ClassType)env.enclClass.type, fa.selected); diff --git a/test/langtools/tools/javac/SuperInit/SuperInitFails.java b/test/langtools/tools/javac/SuperInit/SuperInitFails.java index 77b5db992ee..62bcd268f43 100644 --- a/test/langtools/tools/javac/SuperInit/SuperInitFails.java +++ b/test/langtools/tools/javac/SuperInit/SuperInitFails.java @@ -285,4 +285,26 @@ class Inner9Test extends Medium { } } } + + static class Inner10 { + static boolean testMethod() { return true; } + Inner10() {} + Inner10(int a) { + Inner10.this.testMethod(); + this(); + } + } + + static class Inner11 { + class Inner11_1 { + static void m() {} + } + + class Inner11_2 extends Inner11_1 { + Inner11_2() { + Inner11_1.super.m(); + super(); + } + } + } } diff --git a/test/langtools/tools/javac/SuperInit/SuperInitFails.out b/test/langtools/tools/javac/SuperInit/SuperInitFails.out index eaf099f7fa0..8c525d42432 100644 --- a/test/langtools/tools/javac/SuperInit/SuperInitFails.out +++ b/test/langtools/tools/javac/SuperInit/SuperInitFails.out @@ -28,6 +28,8 @@ SuperInitFails.java:253:13: compiler.err.cant.ref.before.ctor.called: x SuperInitFails.java:266:18: compiler.err.cant.ref.before.ctor.called: x SuperInitFails.java:282:50: compiler.err.cant.ref.before.ctor.called: check SuperInitFails.java:283:39: compiler.err.cant.ref.before.ctor.called: check +SuperInitFails.java:293:25: compiler.err.cant.ref.before.ctor.called: testMethod() +SuperInitFails.java:305:26: compiler.err.not.encl.class: SuperInitFails.Inner11.Inner11_1 SuperInitFails.java:35:13: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:39:14: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:43:14: compiler.err.call.must.only.appear.in.ctor @@ -37,4 +39,4 @@ SuperInitFails.java:55:32: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:85:18: compiler.err.ctor.calls.not.allowed.here SuperInitFails.java:91:13: compiler.err.return.before.superclass.initialized SuperInitFails.java:152:18: compiler.err.call.must.only.appear.in.ctor -39 errors +41 errors diff --git a/test/langtools/tools/javac/SuperInit/SuperInitFailsWarnings.out b/test/langtools/tools/javac/SuperInit/SuperInitFailsWarnings.out index 6017c0cd7ba..f5bcab62c5e 100644 --- a/test/langtools/tools/javac/SuperInit/SuperInitFailsWarnings.out +++ b/test/langtools/tools/javac/SuperInit/SuperInitFailsWarnings.out @@ -8,6 +8,7 @@ SuperInitFails.java:161:15: compiler.err.cant.ref.before.ctor.called: SuperInitF SuperInitFails.java:213:33: compiler.err.ctor.calls.not.allowed.here SuperInitFails.java:253:13: compiler.err.cant.ref.before.ctor.called: x SuperInitFails.java:266:18: compiler.err.cant.ref.before.ctor.called: x +SuperInitFails.java:305:26: compiler.err.not.encl.class: SuperInitFails.Inner11.Inner11_1 SuperInitFails.java:35:13: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:39:14: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:43:14: compiler.err.call.must.only.appear.in.ctor @@ -34,3 +35,4 @@ SuperInitFails.java:232:16: compiler.warn.would.not.be.allowed.in.prologue: x SuperInitFails.java:241:35: compiler.warn.would.not.be.allowed.in.prologue: this SuperInitFails.java:282:50: compiler.warn.would.not.be.allowed.in.prologue: check SuperInitFails.java:283:39: compiler.warn.would.not.be.allowed.in.prologue: check +SuperInitFails.java:293:25: compiler.warn.would.not.be.allowed.in.prologue: testMethod()