mirror of
https://github.com/EsotericSoftware/reflectasm.git
synced 2025-03-29 05:20:25 +08:00
Fix regression in fix for issue #16
ConstructorAccess.get must throw RuntimeException if the no-args constructor is private. The last commit to this class broke the Kryo unit test FieldSerializerTest.testStdInstantiatorStrategy(). Now it works
This commit is contained in:
parent
526526ba01
commit
b96de86918
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.reflectasm;
|
package com.esotericsoftware.reflectasm;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
@ -46,20 +47,29 @@ public abstract class ConstructorAccess<T> {
|
|||||||
String classNameInternal = className.replace('.', '/');
|
String classNameInternal = className.replace('.', '/');
|
||||||
String enclosingClassNameInternal;
|
String enclosingClassNameInternal;
|
||||||
|
|
||||||
|
boolean isPrivate = false;
|
||||||
if (!isNonStaticMemberClass) {
|
if (!isNonStaticMemberClass) {
|
||||||
enclosingClassNameInternal = null;
|
enclosingClassNameInternal = null;
|
||||||
try {
|
try {
|
||||||
type.getDeclaredConstructor((Class[])null);
|
Constructor<T> constructor = type.getDeclaredConstructor((Class[])null);
|
||||||
|
isPrivate = Modifier.isPrivate(constructor.getModifiers());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException("Class cannot be created (missing no-arg constructor): " + type.getName());
|
throw new RuntimeException("Class cannot be created (missing no-arg constructor): " + type.getName(), ex);
|
||||||
|
}
|
||||||
|
if (isPrivate) {
|
||||||
|
throw new RuntimeException("Class cannot be created (the no-arg constructor is private): " + type.getName());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enclosingClassNameInternal = enclosingType.getName().replace('.', '/');
|
enclosingClassNameInternal = enclosingType.getName().replace('.', '/');
|
||||||
try {
|
try {
|
||||||
type.getDeclaredConstructor(enclosingType); // Inner classes should have this.
|
Constructor<T> constructor = type.getDeclaredConstructor(enclosingType); // Inner classes should have this.
|
||||||
|
isPrivate = Modifier.isPrivate(constructor.getModifiers());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException("Non-static member class cannot be created (missing enclosing class constructor): "
|
throw new RuntimeException("Non-static member class cannot be created (missing enclosing class constructor): "
|
||||||
+ type.getName());
|
+ type.getName(), ex);
|
||||||
|
}
|
||||||
|
if (isPrivate) {
|
||||||
|
throw new RuntimeException("Non-static member class cannot be created (the enclosing class constructor is private): " + type.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user