--- a/src/java.base/share/classes/java/lang/reflect/Constructor.java Thu Oct 04 10:19:01 2018 -0700
+++ b/src/java.base/share/classes/java/lang/reflect/Constructor.java Thu Oct 04 13:02:58 2018 -0700
@@ -476,18 +476,27 @@
throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException
{
- if (!override) {
- Class<?> caller = Reflection.getCallerClass();
+ Class<?> caller = override ? null : Reflection.getCallerClass();
+ return newInstanceWithCaller(initargs, !override, caller);
+ }
+
+ /* package-private */
+ T newInstanceWithCaller(Object[] args, boolean checkAccess, Class<?> caller)
+ throws InstantiationException, IllegalAccessException,
+ InvocationTargetException
+ {
+ if (checkAccess)
checkAccess(caller, clazz, clazz, modifiers);
- }
+
if ((clazz.getModifiers() & Modifier.ENUM) != 0)
throw new IllegalArgumentException("Cannot reflectively create enum objects");
+
ConstructorAccessor ca = constructorAccessor; // read volatile
if (ca == null) {
ca = acquireConstructorAccessor();
}
@SuppressWarnings("unchecked")
- T inst = (T) ca.newInstance(initargs);
+ T inst = (T) ca.newInstance(args);
return inst;
}