Permalink
Browse files

JBMAR-137 - Use correct class loader in serializing cloner for readRe…

…solve and readObject methods
  • Loading branch information...
1 parent bd4c170 commit 10360c936aaa4abf4feb4c8c233ceaa79941c1a0 @dmlloyd dmlloyd committed Jun 13, 2012
Showing with 12 additions and 11 deletions.
  1. +12 −11 api/src/main/java/org/jboss/marshalling/cloner/SerializingCloner.java
@@ -181,13 +181,13 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
if (UNCLONED.contains(objClass)) {
return orig;
}
+ final boolean sameClass = objClass == clonedClass;
if (objClass.isArray()) {
Object simpleClone = simpleClone(orig, objClass);
if (simpleClone != null) return simpleClone;
// must be an object array
final Object[] origArray = (Object[]) orig;
final int len = origArray.length;
- final boolean sameClass = objClass == clonedClass;
if (sameClass && len == 0) {
clones.put(orig, orig);
return orig;
@@ -211,6 +211,7 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
return clone;
}
final SerializableClass info = registry.lookup(objClass);
+ final SerializableClass cloneInfo = sameClass ? info : registry.lookup(clonedClass);
if (replace) {
Object replaced = orig;
if (info.hasWriteReplace()) {
@@ -227,7 +228,7 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
final Object clone;
if (orig instanceof Externalizable) {
final Externalizable externalizable = (Externalizable) orig;
- clone = info.callNoArgConstructor();
+ clone = cloneInfo.callNoArgConstructor();
clones.put(orig, clone);
final Queue<Step> steps = new ArrayDeque<Step>();
final StepObjectOutput soo = new StepObjectOutput(steps);
@@ -239,36 +240,36 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
for (nonSerializable = objClass.getSuperclass(); serializabilityChecker.isSerializable(nonSerializable); nonSerializable = nonSerializable.getSuperclass()) {
if (nonSerializable == Object.class) break;
}
- clone = info.callNonInitConstructor(nonSerializable);
+ clone = cloneInfo.callNonInitConstructor(nonSerializable);
final Class<?> cloneClass = clone.getClass();
if (! (serializabilityChecker.isSerializable(cloneClass))) {
throw new NotSerializableException(cloneClass.getName());
}
clones.put(orig, clone);
- initSerializableClone(orig, info, clone, cloneClass);
+ initSerializableClone(orig, info, clone, cloneInfo);
} else {
throw new NotSerializableException(objClass.getName());
}
Object replaced = clone;
- if (info.hasReadResolve()) {
- replaced = info.callReadResolve(replaced);
+ if (cloneInfo.hasReadResolve()) {
+ replaced = cloneInfo.callReadResolve(replaced);
}
replaced = objectResolver.readResolve(replaced);
if (replaced != clone) clones.put(orig, replaced);
return replaced;
}
- private void initSerializableClone(final Object orig, final SerializableClass info, final Object clone, final Class<?> cloneClass) throws IOException, ClassNotFoundException {
+ private void initSerializableClone(final Object orig, final SerializableClass info, final Object clone, final SerializableClass cloneInfo) throws IOException, ClassNotFoundException {
- final Class<?> objClass = info.getSubjectClass();
+ final Class<?> cloneClass = cloneInfo.getSubjectClass();
if (! serializabilityChecker.isSerializable(cloneClass)) {
throw new NotSerializableException(cloneClass.getName());
}
- final SerializableClass cloneInfo = registry.lookup(cloneClass);
final Class<?> cloneSuperClass = cloneClass.getSuperclass();
+ final Class<?> objClass = info.getSubjectClass();
if (cloneClass != clone(objClass)) {
// try superclass first, then fill in "no data"
- initSerializableClone(orig, info, clone, cloneSuperClass);
+ initSerializableClone(orig, info, clone, cloneInfo);
if (cloneInfo.hasReadObjectNoData()) {
cloneInfo.callReadObjectNoData(clone);
}
@@ -277,7 +278,7 @@ private void initSerializableClone(final Object orig, final SerializableClass in
// first, init the serializable superclass, if any
final Class<?> superClass = objClass.getSuperclass();
if (serializabilityChecker.isSerializable(superClass) || serializabilityChecker.isSerializable(cloneSuperClass)) {
- initSerializableClone(orig, registry.lookup(superClass), clone, cloneSuperClass);
+ initSerializableClone(orig, registry.lookup(superClass), clone, registry.lookup(cloneSuperClass));
}
if (! serializabilityChecker.isSerializable(objClass)) {
if (cloneInfo.hasReadObjectNoData()) {

0 comments on commit 10360c9

Please sign in to comment.