private final Constructor mungedConstructor;
public SunReflectionFactorySerializationInstantiator(Class type) {
Class nonSerializableAncestor = SerializationInstantiatorHelper.getNonSerializableSuperClass(type);
ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
Constructor nonSerializableAncestorConstructor;
try {
nonSerializableAncestorConstructor = nonSerializableAncestor
.getConstructor((Class[]) null);
}
catch(NoSuchMethodException e) {
/**
* @todo (Henri) I think we should throw a NotSerializableException just to put the same
* message a ObjectInputStream. Otherwise, the user won't know if the null returned
* if a "Not serializable", a "No default constructor on ancestor" or a "Exception in
* constructor"
*/
throw new ObjenesisException(new NotSerializableException(type+" has no suitable superclass constructor"));
}
mungedConstructor = reflectionFactory.newConstructorForSerialization(type,
nonSerializableAncestorConstructor);
mungedConstructor.setAccessible(true);
}