mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-11 02:48:20 +00:00
8058291: Missing some checks during parameter validation
Reviewed-by: jrose
This commit is contained in:
parent
375020d61a
commit
e490ad1e61
@ -188,7 +188,6 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
||||
static MethodHandle makePairwiseConvert(MethodHandle target, MethodType srcType,
|
||||
boolean strict, boolean monobox) {
|
||||
MethodType dstType = target.type();
|
||||
assert(dstType.parameterCount() == target.type().parameterCount());
|
||||
if (srcType == dstType)
|
||||
return target;
|
||||
if (USE_LAMBDA_FORM_EDITOR) {
|
||||
@ -265,6 +264,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
||||
|
||||
static MethodHandle makePairwiseConvertIndirect(MethodHandle target, MethodType srcType,
|
||||
boolean strict, boolean monobox) {
|
||||
assert(target.type().parameterCount() == srcType.parameterCount());
|
||||
// Calculate extra arguments (temporaries) required in the names array.
|
||||
Object[] convSpecs = computeValueConversions(srcType, target.type(), strict, monobox);
|
||||
final int INARG_COUNT = srcType.parameterCount();
|
||||
|
||||
@ -2023,8 +2023,9 @@ return invoker;
|
||||
*/
|
||||
public static
|
||||
MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
|
||||
MethodType oldType = target.type();
|
||||
explicitCastArgumentsChecks(target, newType);
|
||||
// use the asTypeCache when possible:
|
||||
MethodType oldType = target.type();
|
||||
if (oldType == newType) return target;
|
||||
if (oldType.explicitCastEquivalentToAsType(newType)) {
|
||||
return target.asType(newType);
|
||||
@ -2032,6 +2033,12 @@ return invoker;
|
||||
return MethodHandleImpl.makePairwiseConvert(target, newType, false);
|
||||
}
|
||||
|
||||
private static void explicitCastArgumentsChecks(MethodHandle target, MethodType newType) {
|
||||
if (target.type().parameterCount() != newType.parameterCount()) {
|
||||
throw new WrongMethodTypeException("cannot explicitly cast " + target + " to " + newType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a method handle which adapts the calling sequence of the
|
||||
* given method handle to a new type, by reordering the arguments.
|
||||
@ -2479,6 +2486,7 @@ assertEquals("yz", (String) d0.invokeExact(123, "x", "y", "z"));
|
||||
MethodHandle dropArguments(MethodHandle target, int pos, List<Class<?>> valueTypes) {
|
||||
MethodType oldType = target.type(); // get NPE
|
||||
int dropped = dropArgumentChecks(oldType, pos, valueTypes);
|
||||
MethodType newType = oldType.insertParameterTypes(pos, valueTypes);
|
||||
if (dropped == 0) return target;
|
||||
BoundMethodHandle result = target.rebind();
|
||||
LambdaForm lform = result.form;
|
||||
@ -2490,7 +2498,6 @@ assertEquals("yz", (String) d0.invokeExact(123, "x", "y", "z"));
|
||||
} else {
|
||||
lform = lform.addArguments(pos, valueTypes);
|
||||
}
|
||||
MethodType newType = oldType.insertParameterTypes(pos, valueTypes);
|
||||
result = result.copyWith(newType, lform);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -869,9 +869,7 @@ class MethodType implements java.io.Serializable {
|
||||
if (dstTypes == srcTypes) {
|
||||
return true;
|
||||
}
|
||||
if (dstTypes.length != srcTypes.length) {
|
||||
return false;
|
||||
}
|
||||
assert(dstTypes.length == srcTypes.length);
|
||||
for (int i = 0; i < dstTypes.length; i++) {
|
||||
if (!explicitCastEquivalentToAsType(srcTypes[i], dstTypes[i])) {
|
||||
return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user