diff --git a/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java index 19255494c44..59c1f3f65e9 100644 --- a/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java +++ b/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java @@ -33,8 +33,10 @@ import java.io.FilePermission; import java.lang.reflect.Constructor; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.LinkedHashSet; import java.util.concurrent.atomic.AtomicInteger; import java.util.PropertyPermission; +import java.util.Set; import static jdk.internal.org.objectweb.asm.Opcodes.*; @@ -226,11 +228,20 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; * is not found */ private Class spinInnerClass() throws LambdaConversionException { - String[] interfaces = new String[markerInterfaces.length + 1]; - interfaces[0] = samBase.getName().replace('.', '/'); - for (int i=0; i itfs = new LinkedHashSet<>(markerInterfaces.length + 1); + itfs.add(samIntf); + for (int i = 0; i < markerInterfaces.length; i++) { + itfs.add(markerInterfaces[i].getName().replace('.', '/')); + } + interfaces = itfs.toArray(new String[itfs.size()]); } + cw.visit(CLASSFILE_VERSION, ACC_SUPER + ACC_FINAL + ACC_SYNTHETIC, lambdaClassName, null, JAVA_LANG_OBJECT, interfaces); diff --git a/jdk/test/java/lang/invoke/lambda/DupIntf.java b/jdk/test/java/lang/invoke/lambda/DupIntf.java new file mode 100644 index 00000000000..e7f366e0bd3 --- /dev/null +++ b/jdk/test/java/lang/invoke/lambda/DupIntf.java @@ -0,0 +1,42 @@ +/* + * 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 8025868 + * @summary Lambda class can be generated with duplicate interfaces (ClassFormatError) + * @run main DupIntf + */ + +interface SAM { + P1 m(); +} + +interface Other { } + +public class DupIntf { + public static void main(String argv[]) { + SAM sam = (SAM & Other) () -> "Pass."; + System.out.println(sam.m()); + } +}