PL-7134 Error when deserializing object which uses UserSessionSource in constructor (fix review)

This commit is contained in:
Andrey Subbotin 2016-05-18 15:41:28 +04:00
parent 7c6d2dccb4
commit 7dfead845e

View File

@ -54,6 +54,8 @@ import org.eclipse.persistence.jpa.jpql.parser.DateTime;
import org.objenesis.instantiator.ObjectInstantiator;
import org.objenesis.strategy.InstantiatorStrategy;
import org.objenesis.strategy.StdInstantiatorStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.lang.reflect.Constructor;
@ -71,6 +73,8 @@ import java.util.GregorianCalendar;
*/
public class KryoSerialization implements Serialization {
protected static final Logger log = LoggerFactory.getLogger(KryoSerialization.class);
protected boolean onlySerializable = true;
protected final ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
@Override
@ -247,7 +251,6 @@ public class KryoSerialization implements Serialization {
@Override
public ObjectInstantiator newInstantiatorOf(Class type) {
if (!Util.isAndroid) {
// Use ReflectASM if the class is not a non-static member class.
Class enclosingType = type.getEnclosingClass();
boolean isNonStaticMemberClass = enclosingType != null && type.isMemberClass()
@ -259,13 +262,15 @@ public class KryoSerialization implements Serialization {
try {
return access.newInstance();
} catch (Exception ex) {
if (log.isTraceEnabled()) {
log.trace("Unable instantiate " + Util.className(type), ex);
}
return fallbackStrategy.newInstantiatorOf(type).newInstance();
}
};
} catch (Exception ignored) {
}
}
}
// Reflection.
try {
Constructor ctor;
@ -280,6 +285,9 @@ public class KryoSerialization implements Serialization {
try {
return constructor.newInstance();
} catch (Exception ex) {
if (log.isTraceEnabled()) {
log.trace("Unable instantiate " + Util.className(type), ex);
}
return fallbackStrategy.newInstantiatorOf(type).newInstance();
}
};