mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8242451: ensure semantics of non-capturing lambdas are preserved independent of execution mode
Reviewed-by: mchung
This commit is contained in:
parent
dc1ef58351
commit
1b79326c05
4 changed files with 165 additions and 57 deletions
|
@ -26,15 +26,11 @@
|
|||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* Test bridge methods in certain SAM conversion
|
||||
* Tests that jdk.internal.lambda.disableEagerInitialization=true creates a
|
||||
* get$Lambda method for non-capturing lambdas
|
||||
* @compile BridgeMethod.java
|
||||
* @run main BridgeMethod
|
||||
* @run main/othervm -Djdk.internal.lambda.disableEagerInitialization=true BridgeMethod
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -72,35 +68,19 @@ public class BridgeMethod {
|
|||
return s;
|
||||
}
|
||||
|
||||
private static Set<String> allowedMethods() {
|
||||
Set<String> s = new HashSet<>();
|
||||
s.add("m");
|
||||
return s;
|
||||
}
|
||||
|
||||
private static boolean matchingMethodNames(Method[] methods) {
|
||||
Set<String> methodNames = new HashSet<>();
|
||||
for (Method m : methods) {
|
||||
methodNames.add(m.getName());
|
||||
}
|
||||
return methodNames.equals(allowedMethods());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
L la = BridgeMethod::bar; //static reference
|
||||
la.m("hi");
|
||||
Class<? extends L> c1 = la.getClass();
|
||||
Method[] methods = c1.getDeclaredMethods();
|
||||
assertTrue(matchingMethodNames(methods));
|
||||
Set<String> types = setOfStringObject();
|
||||
System.out.println("methods in SAM conversion of L:");
|
||||
for(Method m : methods) {
|
||||
if (m.getName().equals("m")) {
|
||||
System.out.println(m.toGenericString());
|
||||
Class[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
}
|
||||
assertTrue(m.getName().equals("m"));
|
||||
System.out.println(m.toGenericString());
|
||||
Class[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
}
|
||||
assertTrue(types.isEmpty() || (types.size() == 1 && types.contains("java.lang.String")));
|
||||
|
||||
|
@ -108,16 +88,14 @@ public class BridgeMethod {
|
|||
//km.m("hi"); //will be uncommented when CR7028808 fixed
|
||||
Class<? extends KM> c2 = km.getClass();
|
||||
methods = c2.getDeclaredMethods();
|
||||
assertTrue(matchingMethodNames(methods));
|
||||
types = setOfStringObject();
|
||||
System.out.println("methods in SAM conversion of KM:");
|
||||
for(Method m : methods) {
|
||||
if (m.getName().equals("m")) {
|
||||
System.out.println(m.toGenericString());
|
||||
Class<?>[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
}
|
||||
assertTrue(m.getName().equals("m"));
|
||||
System.out.println(m.toGenericString());
|
||||
Class<?>[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
}
|
||||
assertTrue(types.isEmpty());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue