8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract
authormcimadamore
Fri, 15 Feb 2013 16:28:57 +0000
changeset 16293 bf5e87940aee
parent 16292 3be2cdacb3b3
child 16294 0c291a3cd60d
8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract Summary: Missing abstractness check on super rmethod references Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/lambda/MethodReference62.java
langtools/test/tools/javac/lambda/MethodReference62.out
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Feb 15 16:28:07 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Feb 15 16:28:57 2013 +0000
@@ -2622,8 +2622,11 @@
                 }
             }
 
+            that.sym = refSym.baseSymbol();
+            that.kind = lookupHelper.referenceKind(that.sym);
+
             if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) {
-                if (refSym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) &&
+                if (that.sym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) &&
                         exprType.getTypeArguments().nonEmpty()) {
                     //static ref with class type-args
                     log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()),
@@ -2632,14 +2635,19 @@
                     return;
                 }
 
-                if (refSym.isStatic() && !TreeInfo.isStaticSelector(that.expr, names) &&
-                        !lookupHelper.referenceKind(refSym).isUnbound()) {
+                if (that.sym.isStatic() && !TreeInfo.isStaticSelector(that.expr, names) &&
+                        !that.kind.isUnbound()) {
                     //no static bound mrefs
                     log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()),
                             diags.fragment("static.bound.mref"));
                     result = that.type = types.createErrorType(target);
                     return;
                 }
+
+                if (!refSym.isStatic() && that.kind == JCMemberReference.ReferenceKind.SUPER) {
+                    // Check that super-qualified symbols are not abstract (JLS)
+                    rs.checkNonAbstract(that.pos(), that.sym);
+                }
             }
 
             if (desc.getReturnType() == Type.recoveryType) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/MethodReference62.java	Fri Feb 15 16:28:57 2013 +0000
@@ -0,0 +1,22 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8007285
+ * @summary AbstractMethodError instead of compile-time error when method reference with super and abstract
+ * @compile/fail/ref=MethodReference62.out -XDrawDiagnostics MethodReference62.java
+ */
+class MethodReference62 {
+    interface SAM {
+        int m();
+    }
+
+    static abstract class Sup {
+        abstract int foo() ;
+    }
+
+    static abstract class Sub extends Sup {
+        abstract int foo() ;
+        void test() {
+            SAM s = super::foo;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/MethodReference62.out	Fri Feb 15 16:28:57 2013 +0000
@@ -0,0 +1,2 @@
+MethodReference62.java:19:21: compiler.err.abstract.cant.be.accessed.directly: kindname.method, foo(), MethodReference62.Sup
+1 error