diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-02-06 12:53:58 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-02-06 12:53:59 +0000 |
commit | 0956f88d74eddfdc20c2e51a00093b9ea60760dd (patch) | |
tree | ed661b653a0f0d1f25afcc8de6321cca88ed644c | |
parent | 30824eef475aa2e398f889b497917fc728ffe5ec (diff) | |
parent | d2aa1365d25911076cb174a04b1d5152f0ff80e3 (diff) |
Merge "Port java.lang.invoke.MethodHandles from openJdk80u112"
-rw-r--r-- | ojluni/src/main/java/java/lang/invoke/MethodHandles.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/ojluni/src/main/java/java/lang/invoke/MethodHandles.java b/ojluni/src/main/java/java/lang/invoke/MethodHandles.java index 5b7ca6f228..08b86a0c77 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 @@ package java.lang.invoke; 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 @@ public class MethodHandles { 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 @@ assertEquals("[x, y, z]", pb.command().toString()); * @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 @@ assertEquals("yz", (String) d0.invokeExact(123, "x", "y", "z")); */ 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 @@ assertEquals("yz", (String) d0.invokeExact(123, "x", "y", "z")); 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 @@ System.out.println((int) f0.invokeExact("x", "y")); // 2 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); } |