Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lahodaj committed Aug 30, 2024
1 parent 35b995e commit 2b5900d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
21 changes: 9 additions & 12 deletions src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<?>> methodTypeTypes = new ArrayList<>();
Expand All @@ -3547,16 +3545,15 @@ public MethodHandle unreflectDeconstructor(Deconstructor<?> d) throws IllegalAcc
}
}

private static Object[] carrier2Array(Object carrier, List<MethodHandle> 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<MethodHandle> componentHandles) throws Throwable {
Object[] result = new Object[componentHandles.size()];
int i = 0;

for (MethodHandle componentAccessor : componentHandles) {
result[i++] = componentAccessor.invoke(carrier);
}

return result;
}

/*
Expand Down
11 changes: 7 additions & 4 deletions test/jdk/java/lang/invoke/lookup/UnreflectPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 2b5900d

Please sign in to comment.