8223726: j.l.c.MethodTypeDesc spec should contain precise assertions for one parameter's methods

Reviewed-by: darcy
This commit is contained in:
Vicente Romero 2019-05-16 13:34:33 -04:00
parent 11b6437c01
commit fa2ea6a6d8
4 changed files with 49 additions and 7 deletions
src/java.base/share/classes/java/lang/constant
test/jdk/java/lang/constant

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, 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
@ -177,7 +177,7 @@ public interface MethodHandleDesc
* @param paramTypes {@link ClassDesc}s describing the parameter types of
* the constructor
* @return the {@linkplain MethodHandleDesc}
* @throws NullPointerException if any of the arguments are null
* @throws NullPointerException if any argument or its contents is {@code null}
*/
static DirectMethodHandleDesc ofConstructor(ClassDesc owner,
ClassDesc... paramTypes) {
@ -191,6 +191,7 @@ public interface MethodHandleDesc
*
* @param type a {@link MethodHandleDesc} describing the new method type
* @return a {@linkplain MethodHandleDesc} for the adapted method handle
* @throws NullPointerException if the argument is {@code null}
*/
default MethodHandleDesc asType(MethodTypeDesc type) {
return (invocationType().equals(type)) ? this : new AsTypeMethodHandleDesc(this, type);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, 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
@ -49,7 +49,7 @@ public interface MethodTypeDesc
*
* @param descriptor a method descriptor string
* @return a {@linkplain MethodTypeDesc} describing the desired method type
* @throws NullPointerException if any argument is {@code null}
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if the descriptor string is not a valid
* method descriptor
* @jvms 4.3.3 Method Descriptors
@ -116,7 +116,7 @@ public interface MethodTypeDesc
*
* @param returnType a {@link ClassDesc} describing the new return type
* @return a {@linkplain MethodTypeDesc} describing the desired method type
* @throws NullPointerException if any argument is {@code null}
* @throws NullPointerException if the argument is {@code null}
*/
MethodTypeDesc changeReturnType(ClassDesc returnType);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, 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
@ -152,6 +152,24 @@ public class MethodHandleDescTest extends SymbolicDescTest {
} catch (IllegalArgumentException ex) {
// good
}
// null list of parameters
try {
MethodHandleDesc.ofConstructor(ClassDesc.of("java.util.ArrayList", null));
fail("should have failed: null list of parameters");
} catch (NullPointerException ex) {
// good
}
// null elements in list of parameters
try {
ClassDesc[] paramList = new ClassDesc[1];
paramList[0] = null;
MethodHandleDesc.ofConstructor(ClassDesc.of("java.util.ArrayList"), paramList);
fail("should have failed: null content in list of parameters");
} catch (NullPointerException ex) {
// good
}
}
public void testAsType() throws Throwable {
@ -184,6 +202,13 @@ public class MethodHandleDescTest extends SymbolicDescTest {
MethodHandleDesc same = mhr.asType(mhr.invocationType());
assertSame(mhr, same);
try {
mhr.asType(null);
fail("Expected NPE");
} catch (NullPointerException ex) {
// good
}
// @@@ Test varargs adaptation
// @@@ Test bad adaptations and assert runtime error on resolution
// @@@ Test intrinsification of adapted MH

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, 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
@ -103,6 +103,14 @@ public class MethodTypeDescTest extends SymbolicDescTest {
testMethodTypeDesc(newDesc, mt.changeReturnType((Class<?>)rc.resolveConstantDesc(LOOKUP)));
}
// try with null parameter
try {
MethodTypeDesc newDesc = mtDesc.changeReturnType(null);
fail("should fail with NPE");
} catch (NullPointerException ex) {
// good
}
// changeParamType
for (int i=0; i<paramTypes.length; i++) {
for (String p : paramDescs) {
@ -233,6 +241,14 @@ public class MethodTypeDescTest extends SymbolicDescTest {
}
}
// try with null argument
try {
MethodTypeDesc r = MethodTypeDesc.ofDescriptor(null);
fail("should fail with NPE");
} catch (NullPointerException ex) {
// good
}
// try with void arguments, this will stress another code path in particular
// ConstantMethodTypeDesc::init
try {