mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-172425 Fix bug when default constructor is inaccessible
This commit is contained in:
+38
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user