Skip to content

Commit

Permalink
ConstructorInvoker: Do not call #setAccessible on objects returned by…
Browse files Browse the repository at this point in the history
… Class#getConstructor because Class#getConstutor only returns accessible objects.
  • Loading branch information
PascalSchumacher authored and joel-costigliola committed Aug 3, 2019
1 parent 27f5560 commit 89fa4d5
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions src/main/java/org/assertj/core/error/ConstructorInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
*/
package org.assertj.core.error;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* Access to constructors using Java reflection.
Expand All @@ -30,27 +27,6 @@ public class ConstructorInvoker {
public Object newInstance(String className, Class<?>[] parameterTypes, Object... parameterValues) throws Exception {
Class<?> targetType = Class.forName(className);
Constructor<?> constructor = targetType.getConstructor(parameterTypes);
setAccessible(constructor, true);
return constructor.newInstance(parameterValues);
}

private void setAccessible(AccessibleObject accessible, boolean value) {
AccessController.doPrivileged(new SetAccessibleValueAction(accessible, value));
}

private static class SetAccessibleValueAction implements PrivilegedAction<Void> {
private final AccessibleObject accessible;
private final boolean value;

private SetAccessibleValueAction(AccessibleObject accessible, boolean value) {
this.accessible = accessible;
this.value = value;
}

@Override
public Void run() {
accessible.setAccessible(value);
return null;
}
}
}

0 comments on commit 89fa4d5

Please sign in to comment.