8009582: Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization
authorrfield
Thu, 07 Mar 2013 08:26:13 -0800
changeset 16335 4f7fe060522f
parent 16334 49b3f71982f6
child 16336 cf436a619e34
8009582: Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
langtools/test/tools/javac/lambda/GenericMethodRefImplClass.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 07 10:12:13 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 07 08:26:13 2013 -0800
@@ -558,7 +558,7 @@
         String functionalInterfaceClass = classSig(targetType);
         String functionalInterfaceMethodName = samSym.getSimpleName().toString();
         String functionalInterfaceMethodSignature = methodSig(types.erasure(samSym.type));
-        String implClass = classSig(refSym.owner.type);
+        String implClass = classSig(types.erasure(refSym.owner.type));
         String implMethodName = refSym.getQualifiedName().toString();
         String implMethodSignature = methodSig(types.erasure(refSym.type));
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/GenericMethodRefImplClass.java	Thu Mar 07 08:26:13 2013 -0800
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013, 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
+ * @bug 8009582
+ * @summary Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization
+ * @author  Robert Field
+ * @run main GenericMethodRefImplClass
+ */
+
+import java.io.*;
+import java.util.*;
+
+public class GenericMethodRefImplClass {
+
+    static int assertionCount = 0;
+
+    static void assertTrue(boolean cond) {
+        assertionCount++;
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    public static void main(String[] args) throws Exception {
+        try {
+            // Write lambdas out
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutput out = new ObjectOutputStream(baos);
+
+            write(out, HashMap::new );
+            out.flush();
+            out.close();
+
+            // Read them back
+            ByteArrayInputStream bais =
+                new ByteArrayInputStream(baos.toByteArray());
+            ObjectInputStream in = new ObjectInputStream(bais);
+            readIt(in);
+            in.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw e;
+        }
+        assertTrue(assertionCount == 1);
+    }
+
+    static void write(ObjectOutput out, GenericMethodRefImplClassLSI lamb) throws IOException {
+        out.writeObject(lamb);
+    }
+
+    static void readIt(ObjectInputStream in)  throws IOException, ClassNotFoundException {
+        GenericMethodRefImplClassLSI ls = (GenericMethodRefImplClassLSI) in.readObject();
+        Map result = ls.convert();
+        assertTrue(result.getClass().getName().equals("java.util.HashMap"));
+    }
+}
+
+interface GenericMethodRefImplClassLSI extends Serializable {
+    Map convert();
+}