From 2b5900d5049c94c02bd6e5923a6234533ce56497 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Fri, 30 Aug 2024 10:07:24 +0200 Subject: [PATCH] Cleanup. --- .../java/lang/invoke/MethodHandles.java | 21 ++++++++----------- .../lang/invoke/lookup/UnreflectPattern.java | 11 ++++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java index 708e0dcb4f8c5..3c5c1ef744658 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java @@ -3520,8 +3520,6 @@ public MethodHandle unreflectConstructor(Constructor c) throws IllegalAccessE public MethodHandle unreflectDeconstructor(Deconstructor d) throws IllegalAccessException { try { String mangled = SharedSecrets.getJavaLangReflectAccess().getMangledName(d); - @SuppressWarnings("deprecation") - Lookup lookup = d.isAccessible() ? IMPL_LOOKUP : this; Method deconstructorMethod = d.getDeclaringClass().getDeclaredMethod(mangled, d.getDeclaringClass()); MethodHandle deconstructorPhysicalHandle = unreflect(deconstructorMethod); List> methodTypeTypes = new ArrayList<>(); @@ -3547,16 +3545,15 @@ public MethodHandle unreflectDeconstructor(Deconstructor d) throws IllegalAcc } } - private static Object[] carrier2Array(Object carrier, List componentHandles) { - return componentHandles.stream() - .map(componentAccess -> { - try { - return componentAccess.invoke(carrier); - } catch (Throwable t) { - throw new IllegalStateException(t); - } - }) - .toArray(Object[]::new); + private static Object[] carrier2Array(Object carrier, List componentHandles) throws Throwable { + Object[] result = new Object[componentHandles.size()]; + int i = 0; + + for (MethodHandle componentAccessor : componentHandles) { + result[i++] = componentAccessor.invoke(carrier); + } + + return result; } /* diff --git a/test/jdk/java/lang/invoke/lookup/UnreflectPattern.java b/test/jdk/java/lang/invoke/lookup/UnreflectPattern.java index 24f4eb3389cdb..d534d47a28167 100644 --- a/test/jdk/java/lang/invoke/lookup/UnreflectPattern.java +++ b/test/jdk/java/lang/invoke/lookup/UnreflectPattern.java @@ -27,8 +27,6 @@ * @compile UnreflectPattern.java * @run main UnreflectPattern */ -// * @run main test.java.lang.invoke.lookup.UnreflectPattern -//package test.java.lang.invoke.lookup; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -38,13 +36,18 @@ public class UnreflectPattern { public static void main(String... args) throws Throwable { + Object[] expected = new Object[] {"correct", -1}; Object instance = new UnreflectPattern(); Deconstructor deconstructor = UnreflectPattern.class.getDeclaredDeconstructor(String.class, int.class); Object[] result1 = deconstructor.invoke(instance); - System.err.println(Arrays.asList(result1)); + if (!Arrays.equals(expected, result1)) { + throw new AssertionError("Unexpected result: " + Arrays.toString(result1)); + } MethodHandle deconstructorHandle = MethodHandles.lookup().unreflectDeconstructor(deconstructor); Object[] result2 = (Object[]) deconstructorHandle.invoke(instance); - System.err.println(Arrays.asList(result2)); + if (!Arrays.equals(expected, result2)) { + throw new AssertionError("Unexpected result: " + Arrays.toString(result2)); + } } public pattern UnreflectPattern(String s, int i) {