changeset 933:c80ead80fcfd

Fixed SAM conversion for corner case involving abstract classes implementing ''target'' abstract method. This is just for completeness, given that abstract classes support in SAM conversion has been dropped.
author mcimadamore
date Mon, 07 Mar 2011 11:50:39 +0000
parents 5aeda537bf98
children 1623ce0ec047
files src/share/classes/com/sun/tools/javac/code/Types.java test/tools/javac/lambda/LambdaConv15.java
diffstat 2 files changed, 64 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Mar 01 17:48:13 2011 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Mar 07 11:50:39 2011 +0000
@@ -463,13 +463,15 @@
                     (e.sym.flags() & DEFENDER) == 0 &&
                     (!t.isInterface() || !overridesObjectMethod(e.sym, t.tsym))) {
                 MethodSymbol msym = (MethodSymbol)e.sym;
-                if (buf.isEmpty() ||
-                        (msym.name == buf.first().name &&
-                        msym.implementation(site.tsym, this, false) != null &&
-                        overrideEquivalent(msym.implementation(site.tsym, this, false).type, buf.first().type))) {
-                    buf.append(e.sym);
+                Symbol impl = msym.implementation(site.tsym, this, false);
+                if (impl == null || (impl.flags() & ABSTRACT) != 0) {
+                    count++;
+                    if (buf.isEmpty() ||
+                            (msym.name == buf.first().name &&
+                            overrideEquivalent(impl.type, buf.first().type))) {
+                        buf.append(e.sym);
+                    }
                 }
-                count++;
             }
         }
         count += findSAM(site, supertype(t), buf, seenTypes);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/LambdaConv15.java	Mon Mar 07 11:50:39 2011 +0000
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary test for abstract SAM that implements ''target'' method
+ * @author  Maurizio Cimadamore
+ * @compile -XDabstractSAM LambdaConv15.java
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles LambdaConv15
+ */
+
+public class LambdaConv15 {
+
+    static int assertionCount = 0;
+
+    static void assertTrue(boolean cond) {
+        assertionCount++;
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    void test(){
+        SAM sam = #{ assertTrue(true); };
+        sam.test();
+    }
+
+    static abstract class SAM implements Comparable<SAM> {
+        public int compareTo(SAM a) { return -1; }
+        abstract void test();
+    }
+
+    public static void main(String[] args) {
+        new LambdaConv15().test();
+        assertTrue(assertionCount == 1);
+    }
+}