8059921: Missing compile error in Java 8 mode for Interface.super.field access
authorvromero
Thu, 20 Nov 2014 09:43:13 -0800
changeset 27845 afce9de2de10
parent 27844 8b5d79870a2f
child 27846 8a7a3a187e24
child 27847 7f19affabf41
8059921: Missing compile error in Java 8 mode for Interface.super.field access Reviewed-by: mcimadamore, jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.java
langtools/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Nov 19 13:46:04 2014 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Nov 20 09:43:13 2014 -0800
@@ -3233,6 +3233,10 @@
         // Determine the symbol represented by the selection.
         env.info.pendingResolutionPhase = null;
         Symbol sym = selectSym(tree, sitesym, site, env, resultInfo);
+        if (sym.kind == VAR && sym.name != names._super && env.info.defaultSuperCallSite != null) {
+            log.error(tree.selected.pos(), "not.encl.class", site.tsym);
+            sym = syms.errSymbol;
+        }
         if (sym.exists() && !isType(sym) && pkind().contains(KindSelector.TYP_PCK)) {
             site = capture(site);
             sym = selectSym(tree, sitesym, site, env, resultInfo);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.java	Thu Nov 20 09:43:13 2014 -0800
@@ -0,0 +1,31 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8059921
+ * @summary Missing compile error in Java 8 mode for Interface.super.field access
+ * @compile/fail/ref=ForbidAccessToFieldUsingSuperTest.out -XDrawDiagnostics ForbidAccessToFieldUsingSuperTest.java
+ */
+
+public class ForbidAccessToFieldUsingSuperTest {
+    class C {
+        int m() { return 0; }
+    }
+
+    interface T {
+        int f = 0;
+        C c = null;
+        default int mm() {
+            return 0;
+        }
+    }
+
+    interface T1 extends T {}
+
+    class X implements T1 {
+        int i = T1.super.f;        //fail
+        int j = T1.super.c.m();    //fail
+
+        void foo(Runnable r) {
+            foo(T1.super::mm);     //should'n fail
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.out	Thu Nov 20 09:43:13 2014 -0800
@@ -0,0 +1,3 @@
+ForbidAccessToFieldUsingSuperTest.java:24:19: compiler.err.not.encl.class: ForbidAccessToFieldUsingSuperTest.T1
+ForbidAccessToFieldUsingSuperTest.java:25:19: compiler.err.not.encl.class: ForbidAccessToFieldUsingSuperTest.T1
+2 errors