ConstructorInvoker: Do not call #setAccessible on objects returned by Class#getConstructor because Class#getConstutor only returns accessible objects.
*/
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.
@@ -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;
- }
- }
}
