aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlivanov <none@none>2014-12-09 09:22:07 -0800
committervlivanov <none@none>2014-12-09 09:22:07 -0800
commitdbebd7497ff54fbba26fa03eaa8cda0418f24ea3 (patch)
treecea4cdad4ffc6ef95bd4dad55185b4d190b25aac
parente7a2ea5c80d41ffb1e135e0c1ec442f750de3590 (diff)
downloadjdk8u_jdk-dbebd7497ff54fbba26fa03eaa8cda0418f24ea3.tar.gz
8066746: MHs.explicitCastArguments does incorrect type checks for VarargsCollector
Reviewed-by: jrose, psandoz
-rw-r--r--src/share/classes/java/lang/invoke/MethodHandles.java2
-rw-r--r--test/java/lang/invoke/ExplicitCastArgumentsTest.java21
2 files changed, 19 insertions, 4 deletions
diff --git a/src/share/classes/java/lang/invoke/MethodHandles.java b/src/share/classes/java/lang/invoke/MethodHandles.java
index 3c60a8c3c9..8511890481 100644
--- a/src/share/classes/java/lang/invoke/MethodHandles.java
+++ b/src/share/classes/java/lang/invoke/MethodHandles.java
@@ -2029,7 +2029,7 @@ return invoker;
MethodType oldType = target.type();
if (oldType == newType) return target;
if (oldType.explicitCastEquivalentToAsType(newType)) {
- return target.asType(newType);
+ return target.asFixedArity().asType(newType);
}
return MethodHandleImpl.makePairwiseConvert(target, newType, false);
}
diff --git a/test/java/lang/invoke/ExplicitCastArgumentsTest.java b/test/java/lang/invoke/ExplicitCastArgumentsTest.java
index 06f7a64aab..045ec15599 100644
--- a/test/java/lang/invoke/ExplicitCastArgumentsTest.java
+++ b/test/java/lang/invoke/ExplicitCastArgumentsTest.java
@@ -32,21 +32,36 @@ import sun.invoke.util.Wrapper;
*/
public class ExplicitCastArgumentsTest {
private static final boolean VERBOSE = Boolean.getBoolean("verbose");
+ private static final Class<?> THIS_CLASS = ExplicitCastArgumentsTest.class;
public static void main(String[] args) throws Throwable {
+ testVarargsCollector();
+ testRef2Prim();
+ System.out.println("TEST PASSED");
+ }
+
+ public static String[] f(String... args) { return args; }
+
+ public static void testVarargsCollector() throws Throwable {
+ MethodType mt = MethodType.methodType(String[].class, String[].class);
+ MethodHandle mh = MethodHandles.publicLookup().findStatic(THIS_CLASS, "f", mt);
+ mh = MethodHandles.explicitCastArguments(mh, MethodType.methodType(Object.class, Object.class));
+ mh.invokeWithArguments((Object)(new String[] {"str1", "str2"}));
+ }
+
+ public static void testRef2Prim() throws Throwable {
for (Wrapper from : Wrapper.values()) {
for (Wrapper to : Wrapper.values()) {
if (from == Wrapper.VOID || to == Wrapper.VOID) continue;
- testRef2Prim (from, to);
+ testRef2Prim(from, to);
}
}
- System.out.println("TEST PASSED");
}
public static void testRef2Prim(Wrapper from, Wrapper to) throws Throwable {
// MHs.eCA javadoc:
// If T0 is a reference and T1 a primitive, and if the reference is null at runtime, a zero value is introduced.
- test(from.wrapperType(), to.primitiveType(), null, false);
+ test(from.wrapperType(), to.primitiveType(), null, false);
}
public static void test(Class<?> from, Class<?> to, Object param, boolean failureExpected) throws Throwable {