From efddb3dad3691f35e5e9d1c22c83c37b778e0197 Mon Sep 17 00:00:00 2001 From: rfield Date: Wed, 23 Oct 2013 15:16:35 -0700 Subject: [PATCH] 8025868: Several lang/LMBD JCK tests fail with java.lang.BootstrapMethodError Summary: Wildcard marker interfaces can cause duplicate implemented interfaces in generated lambda class Reviewed-by: briangoetz --- .../invoke/InnerClassLambdaMetafactory.java | 19 +++++++-- test/java/lang/invoke/lambda/DupIntf.java | 42 +++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 test/java/lang/invoke/lambda/DupIntf.java diff --git a/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java index 19255494c..59c1f3f65 100644 --- a/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java +++ b/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/test/java/lang/invoke/lambda/DupIntf.java b/test/java/lang/invoke/lambda/DupIntf.java new file mode 100644 index 000000000..e7f366e0b --- /dev/null +++ b/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()); + } +} -- GitLab