IDEA-172425 Fix bug when default constructor is inaccessible

This commit is contained in:
Vitaliy.Bibaev
2018-03-27 12:11:27 +03:00
parent de907c6cd3
commit 9912c9b6b3
4 changed files with 48 additions and 2 deletions
@@ -0,0 +1,38 @@
call text: Inner result = Test.invoke();
class:
static class Test {
static Inner invoke() {
return newWithReflectionAccess$Inner1();
}
public static Object newWithReflectionAccess$Inner1() {
try {
Class<?> klass = Class.forName("WithReflectionAccess$Inner");
java.lang.reflect.Constructor<?> member = null;
int interfaceNumber = -1;
Class<?>[] interfaces = null;
while (member == null) {
try {
member = klass.getDeclaredConstructor();
} catch (ReflectiveOperationException e) {
if (interfaceNumber == -1) {
interfaces = klass.getInterfaces();
interfaceNumber = 0;
}
if (interfaceNumber < interfaces.length) {
klass = interfaces[interfaceNumber];
interfaceNumber += 1;
} else {
klass = klass.getSuperclass();
if (klass == null) throw e;
interfaceNumber = -1;
}
}
}
member.setAccessible(true);
return (Object) member.newInstance();
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
}