8223803: j.l.c.MethodTypeDesc::insertParameterTypes​ doesn't control type of parameters

Reviewed-by: rriggs
This commit is contained in:
Vicente Romero 2019-05-17 13:16:07 -04:00
parent 092bb9e108
commit 917645194b
3 changed files with 37 additions and 2 deletions

View File

@ -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
@ -97,6 +97,11 @@ public interface ConstantDesc {
* @throws ReflectiveOperationException if a class, method, or field
* could not be reflectively resolved in the course of resolution
* @throws LinkageError if a linkage error occurs
*
* @apiNote {@linkplain MethodTypeDesc} can represent method type descriptors
* that are not representable by {@linkplain MethodType}, such as methods with
* more than 255 parameter slots, so attempts to resolve these may result in errors.
*
* @jvms 5.4.3 Resolution
* @jvms 5.4.4 Access Control
*/

View File

@ -154,9 +154,11 @@ public interface MethodTypeDesc
* @param paramTypes {@link ClassDesc}s describing the new parameter types
* to insert
* @return a {@linkplain MethodTypeDesc} describing the desired method type
* @throws NullPointerException if any argument is {@code null}
* @throws NullPointerException if any argument or its contents are {@code null}
* @throws IndexOutOfBoundsException if {@code pos} is outside the closed
* range {[0, parameterCount]}
* @throws IllegalArgumentException if any element of {@code paramTypes}
* is a {@link ClassDesc} for {@code void}
*/
MethodTypeDesc insertParameterTypes(int pos, ClassDesc... paramTypes);

View File

@ -171,6 +171,34 @@ public class MethodTypeDescTest extends SymbolicDescTest {
} catch (IndexOutOfBoundsException ex) {
// good
}
try {
ClassDesc[] newParamTypes = new ClassDesc[1];
newParamTypes[0] = CD_void;
MethodTypeDesc newDesc = MethodTypeDesc.of(returnType, CD_int);
newDesc = newDesc.insertParameterTypes(0, newParamTypes);
fail("shouldn't allow parameters with class descriptor CD_void");
} catch (IllegalArgumentException ex) {
// good
}
try {
MethodTypeDesc newDesc = MethodTypeDesc.of(returnType, CD_int);
newDesc = newDesc.insertParameterTypes(0, null);
fail("should fail with NPE");
} catch (NullPointerException ex) {
// good
}
try {
ClassDesc[] newParamTypes = new ClassDesc[1];
newParamTypes[0] = null;
MethodTypeDesc newDesc = MethodTypeDesc.of(returnType, CD_int);
newDesc = newDesc.insertParameterTypes(0, newParamTypes);
fail("should fail with NPE");
} catch (NullPointerException ex) {
// good
}
}
private void badDropParametersTypes(ClassDesc returnType, String... paramDescTypes) {