8025868: Several lang/LMBD JCK tests fail with java.lang.BootstrapMethodError

Wildcard marker interfaces can cause duplicate implemented interfaces in generated lambda class

Reviewed-by: briangoetz
This commit is contained in:
Robert Field 2013-10-23 15:16:35 -07:00
parent 96e2b92fb1
commit 80ce6f3ec5
2 changed files with 57 additions and 4 deletions

View File

@ -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<markerInterfaces.length; i++) {
interfaces[i+1] = markerInterfaces[i].getName().replace('.', '/');
String[] interfaces;
String samIntf = samBase.getName().replace('.', '/');
if (markerInterfaces.length == 0) {
interfaces = new String[]{samIntf};
} else {
// Assure no duplicate interfaces (ClassFormatError)
Set<String> 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);

View File

@ -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> {
P1 m();
}
interface Other { }
public class DupIntf {
public static void main(String argv[]) {
SAM<?> sam = (SAM<?> & Other) () -> "Pass.";
System.out.println(sam.m());
}
}