8009582: Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization

Thu, 07 Mar 2013 08:26:13 -0800

author
rfield
date
Thu, 07 Mar 2013 08:26:13 -0800
changeset 1622
a02c3ddc182b
parent 1621
823fb9229724
child 1623
c61add6bf8ac

8009582: Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/GenericMethodRefImplClass.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 07 10:12:13 2013 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 07 08:26:13 2013 -0800
     1.3 @@ -558,7 +558,7 @@
     1.4          String functionalInterfaceClass = classSig(targetType);
     1.5          String functionalInterfaceMethodName = samSym.getSimpleName().toString();
     1.6          String functionalInterfaceMethodSignature = methodSig(types.erasure(samSym.type));
     1.7 -        String implClass = classSig(refSym.owner.type);
     1.8 +        String implClass = classSig(types.erasure(refSym.owner.type));
     1.9          String implMethodName = refSym.getQualifiedName().toString();
    1.10          String implMethodSignature = methodSig(types.erasure(refSym.type));
    1.11  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/lambda/GenericMethodRefImplClass.java	Thu Mar 07 08:26:13 2013 -0800
     2.3 @@ -0,0 +1,81 @@
     2.4 +/*
     2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug 8009582
    2.30 + * @summary Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization
    2.31 + * @author  Robert Field
    2.32 + * @run main GenericMethodRefImplClass
    2.33 + */
    2.34 +
    2.35 +import java.io.*;
    2.36 +import java.util.*;
    2.37 +
    2.38 +public class GenericMethodRefImplClass {
    2.39 +
    2.40 +    static int assertionCount = 0;
    2.41 +
    2.42 +    static void assertTrue(boolean cond) {
    2.43 +        assertionCount++;
    2.44 +        if (!cond)
    2.45 +            throw new AssertionError();
    2.46 +    }
    2.47 +
    2.48 +    public static void main(String[] args) throws Exception {
    2.49 +        try {
    2.50 +            // Write lambdas out
    2.51 +            ByteArrayOutputStream baos = new ByteArrayOutputStream();
    2.52 +            ObjectOutput out = new ObjectOutputStream(baos);
    2.53 +
    2.54 +            write(out, HashMap::new );
    2.55 +            out.flush();
    2.56 +            out.close();
    2.57 +
    2.58 +            // Read them back
    2.59 +            ByteArrayInputStream bais =
    2.60 +                new ByteArrayInputStream(baos.toByteArray());
    2.61 +            ObjectInputStream in = new ObjectInputStream(bais);
    2.62 +            readIt(in);
    2.63 +            in.close();
    2.64 +        } catch (IOException e) {
    2.65 +            e.printStackTrace();
    2.66 +            throw e;
    2.67 +        }
    2.68 +        assertTrue(assertionCount == 1);
    2.69 +    }
    2.70 +
    2.71 +    static void write(ObjectOutput out, GenericMethodRefImplClassLSI lamb) throws IOException {
    2.72 +        out.writeObject(lamb);
    2.73 +    }
    2.74 +
    2.75 +    static void readIt(ObjectInputStream in)  throws IOException, ClassNotFoundException {
    2.76 +        GenericMethodRefImplClassLSI ls = (GenericMethodRefImplClassLSI) in.readObject();
    2.77 +        Map result = ls.convert();
    2.78 +        assertTrue(result.getClass().getName().equals("java.util.HashMap"));
    2.79 +    }
    2.80 +}
    2.81 +
    2.82 +interface GenericMethodRefImplClassLSI extends Serializable {
    2.83 +    Map convert();
    2.84 +}

mercurial