OpenJDK / amber / amber
changeset 50736:ed6fdf96e5fa jep-334
adding tests to MethodTypeRefTest
author | vromero |
---|---|
date | Thu, 24 May 2018 09:56:02 -0700 |
parents | fc28ca68554e |
children | cd7f4c80a4db |
files | test/jdk/java/lang/invoke/constant/MethodTypeRefTest.java |
diffstat | 1 files changed, 77 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/test/jdk/java/lang/invoke/constant/MethodTypeRefTest.java Thu May 24 08:09:36 2018 -0700 +++ b/test/jdk/java/lang/invoke/constant/MethodTypeRefTest.java Thu May 24 09:56:02 2018 -0700 @@ -33,6 +33,8 @@ import org.testng.annotations.Test; +import static java.lang.invoke.constant.ConstantDescs.CR_int; +import static java.lang.invoke.constant.ConstantDescs.CR_void; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; import static org.testng.Assert.assertEquals; @@ -127,6 +129,8 @@ testMethodTypeRef(newRef, mt.dropParameterTypes(i, i+1)); } + badDropParametersTypes(CR_void, paramDescs); + // addParam for (int i=0; i <= paramTypes.length; i++) { for (ClassDesc p : paramTypes) { @@ -139,6 +143,69 @@ testMethodTypeRef(newRef, mt.insertParameterTypes(i, p.resolveConstantDesc(LOOKUP))); } } + + badInsertParametersTypes(CR_void, paramDescs); + } + + private void badInsertParametersTypes(ClassDesc returnType, String... paramDescTypes) { + ClassDesc[] paramTypes = + IntStream.rangeClosed(0, paramDescTypes.length - 1) + .mapToObj(i -> ClassDesc.ofDescriptor(paramDescTypes[i])).toArray(ClassDesc[]::new); + MethodTypeDesc mtRef = MethodTypeDesc.of(returnType, paramTypes); + try { + MethodTypeDesc newRef = mtRef.insertParameterTypes(-1, paramTypes); + fail("pos < 0 should have failed"); + } catch (IndexOutOfBoundsException ex) { + // good + } + + try { + MethodTypeDesc newRef = mtRef.insertParameterTypes(paramTypes.length + 1, paramTypes); + fail("pos > current arguments length should have failed"); + } catch (IndexOutOfBoundsException ex) { + // good + } + } + + private void badDropParametersTypes(ClassDesc returnType, String... paramDescTypes) { + ClassDesc[] paramTypes = + IntStream.rangeClosed(0, paramDescTypes.length - 1) + .mapToObj(i -> ClassDesc.ofDescriptor(paramDescTypes[i])).toArray(ClassDesc[]::new); + MethodTypeDesc mtRef = MethodTypeDesc.of(returnType, paramTypes); + try { + MethodTypeDesc newRef = mtRef.dropParameterTypes(-1, 0); + fail("start index < 0 should have failed"); + } catch (IndexOutOfBoundsException ex) { + // good + } + + try { + MethodTypeDesc newRef = mtRef.dropParameterTypes(paramTypes.length, 0); + fail("start index = arguments.length should have failed"); + } catch (IndexOutOfBoundsException ex) { + // good + } + + try { + MethodTypeDesc newRef = mtRef.dropParameterTypes(paramTypes.length + 1, 0); + fail("start index > arguments.length should have failed"); + } catch (IndexOutOfBoundsException ex) { + // good + } + + try { + MethodTypeDesc newRef = mtRef.dropParameterTypes(0, paramTypes.length + 1); + fail("end index > arguments.length should have failed"); + } catch (IndexOutOfBoundsException ex) { + // good + } + + try { + MethodTypeDesc newRef = mtRef.dropParameterTypes(1, 0); + fail("start index > end index should have failed"); + } catch (IllegalArgumentException ex) { + // good + } } public void testMethodTypeRef() throws ReflectiveOperationException { @@ -167,5 +234,15 @@ // good } } + + // try with void arguments, this will stress another code path in particular + // ConstantMethodTypeDesc::init + try { + MethodTypeDesc r = MethodTypeDesc.of(CR_int, CR_void); + fail("can't reach here"); + } + catch (IllegalArgumentException e) { + // good + } } }