Merge "Port java.lang.invoke.MethodHandles from openJdk80u112"
diff --git a/ojluni/src/main/java/java/lang/invoke/MethodHandles.java b/ojluni/src/main/java/java/lang/invoke/MethodHandles.java
index 5b7ca6f..08b86a0 100644
--- a/ojluni/src/main/java/java/lang/invoke/MethodHandles.java
+++ b/ojluni/src/main/java/java/lang/invoke/MethodHandles.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, 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
@@ -28,6 +28,7 @@
import java.lang.reflect.*;
import java.util.List;
import java.util.Arrays;
+import java.util.ArrayList;
import java.util.NoSuchElementException;
import dalvik.system.VMStack;
@@ -678,7 +679,9 @@
if (allowedModes == ALL_MODES &&
lookupClass.getClassLoader() == Object.class.getClassLoader()) {
if (name.startsWith("java.") ||
- (name.startsWith("sun.") && !name.startsWith("sun.invoke."))) {
+ (name.startsWith("sun.")
+ && !name.startsWith("sun.invoke.")
+ && !name.equals("sun.reflect.ReflectionFactory"))) {
throw newIllegalArgumentException("illegal lookupClass: " + lookupClass);
}
}
@@ -957,6 +960,9 @@
* @throws NullPointerException if any argument is null
*/
public MethodHandle findConstructor(Class<?> refc, MethodType type) throws NoSuchMethodException, IllegalAccessException {
+ if (refc.isArray()) {
+ throw new NoSuchMethodException("no constructor for array class: " + refc.getName());
+ }
// The queried |type| is (PT1,PT2,..)V
Constructor constructor = refc.getDeclaredConstructor(type.ptypes());
if (constructor == null) {
@@ -2276,6 +2282,7 @@
*/
public static
MethodHandle dropArguments(MethodHandle target, int pos, List<Class<?>> valueTypes) {
+ valueTypes = copyTypes(valueTypes);
MethodType oldType = target.type(); // get NPE
int dropped = dropArgumentChecks(oldType, pos, valueTypes);
@@ -2287,6 +2294,11 @@
return new Transformers.DropArguments(newType, target, pos, valueTypes.size());
}
+ private static List<Class<?>> copyTypes(List<Class<?>> types) {
+ Object[] a = types.toArray();
+ return Arrays.asList(Arrays.copyOf(a, a.length, Class[].class));
+ }
+
private static int dropArgumentChecks(MethodType oldType, int pos, List<Class<?>> valueTypes) {
int dropped = valueTypes.size();
MethodType.checkSlotCount(dropped);
@@ -2643,7 +2655,7 @@
int filterValues = filterType.parameterCount();
if (filterValues == 0
? (rtype != void.class)
- : (rtype != filterType.parameterType(0)))
+ : (rtype != filterType.parameterType(0) || filterValues != 1))
throw newIllegalArgumentException("target and filter types do not match", targetType, filterType);
}