Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…solve and readObject methods
  • Loading branch information...
commit 2e276bc2273d9b105dda7e48ec011059caa212ee 1 parent fee1b25
David M. Lloyd authored June 13, 2012
28  api/src/main/java/org/jboss/marshalling/cloner/SerializingCloner.java
@@ -190,13 +190,13 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
190 190
         if (UNCLONED.contains(objClass)) {
191 191
             return orig;
192 192
         }
  193
+        final boolean sameClass = objClass == clonedClass;
193 194
         if (objClass.isArray()) {
194 195
             Object simpleClone = simpleClone(orig, objClass);
195 196
             if (simpleClone != null) return simpleClone;
196 197
             // must be an object array
197 198
             final Object[] origArray = (Object[]) orig;
198 199
             final int len = origArray.length;
199  
-            final boolean sameClass = objClass == clonedClass;
200 200
             if (sameClass && len == 0) {
201 201
                 clones.put(orig, orig);
202 202
                 return orig;
@@ -220,6 +220,7 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
220 220
             return clone;
221 221
         }
222 222
         final SerializableClass info = registry.lookup(objClass);
  223
+        final SerializableClass cloneInfo = sameClass ? info : registry.lookup(clonedClass);
223 224
         if (replace) {
224 225
             Object replaced = orig;
225 226
             if (info.hasWriteReplace()) {
@@ -236,7 +237,7 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
236 237
         final Object clone;
237 238
         if (orig instanceof Externalizable) {
238 239
             final Externalizable externalizable = (Externalizable) orig;
239  
-            clone = externalizedCreator.create((Class<?>) clone(objClass));
  240
+            clone = externalizedCreator.create(clonedClass);
240 241
             clones.put(orig, clone);
241 242
             final Queue<Step> steps = new ArrayDeque<Step>();
242 243
             final StepObjectOutput soo = new StepObjectOutput(steps);
@@ -244,36 +245,35 @@ private Object clone(final Object orig, final boolean replace) throws IOExceptio
244 245
             soo.doFinish();
245 246
             ((Externalizable) clone).readExternal(new StepObjectInput(steps));
246 247
         } else if (serializabilityChecker.isSerializable(objClass)) {
247  
-            clone = serializedCreator.create((Class<?>) clone(objClass));
248  
-            final Class<?> cloneClass = clone.getClass();
249  
-            if (! (serializabilityChecker.isSerializable(cloneClass))) {
250  
-                throw new NotSerializableException(cloneClass.getName());
  248
+            clone = serializedCreator.create(clonedClass);
  249
+            if (! (serializabilityChecker.isSerializable(clonedClass))) {
  250
+                throw new NotSerializableException(clonedClass.getName());
251 251
             }
252 252
             clones.put(orig, clone);
253  
-            initSerializableClone(orig, info, clone, cloneClass);
  253
+            initSerializableClone(orig, info, clone, cloneInfo);
254 254
         } else {
255 255
             throw new NotSerializableException(objClass.getName());
256 256
         }
257 257
         Object replaced = clone;
258  
-        if (info.hasReadResolve()) {
259  
-            replaced = info.callReadResolve(replaced);
  258
+        if (cloneInfo.hasReadResolve()) {
  259
+            replaced = cloneInfo.callReadResolve(replaced);
260 260
         }
261 261
         replaced = objectResolver.readResolve(replaced);
262 262
         if (replaced != clone) clones.put(orig, replaced);
263 263
         return replaced;
264 264
     }
265 265
 
266  
-    private void initSerializableClone(final Object orig, final SerializableClass info, final Object clone, final Class<?> cloneClass) throws IOException, ClassNotFoundException {
  266
+    private void initSerializableClone(final Object orig, final SerializableClass info, final Object clone, final SerializableClass cloneInfo) throws IOException, ClassNotFoundException {
267 267
 
268  
-        final Class<?> objClass = info.getSubjectClass();
  268
+        final Class<?> cloneClass = cloneInfo.getSubjectClass();
269 269
         if (! serializabilityChecker.isSerializable(cloneClass)) {
270 270
             throw new NotSerializableException(cloneClass.getName());
271 271
         }
272  
-        final SerializableClass cloneInfo = registry.lookup(cloneClass);
273 272
         final Class<?> cloneSuperClass = cloneClass.getSuperclass();
  273
+        final Class<?> objClass = info.getSubjectClass();
274 274
         if (cloneClass != clone(objClass)) {
275 275
             // try superclass first, then fill in "no data"
276  
-            initSerializableClone(orig, info, clone, cloneSuperClass);
  276
+            initSerializableClone(orig, info, clone, cloneInfo);
277 277
             if (cloneInfo.hasReadObjectNoData()) {
278 278
                 cloneInfo.callReadObjectNoData(clone);
279 279
             }
@@ -282,7 +282,7 @@ private void initSerializableClone(final Object orig, final SerializableClass in
282 282
         // first, init the serializable superclass, if any
283 283
         final Class<?> superClass = objClass.getSuperclass();
284 284
         if (serializabilityChecker.isSerializable(superClass) || serializabilityChecker.isSerializable(cloneSuperClass)) {
285  
-            initSerializableClone(orig, registry.lookup(superClass), clone, cloneSuperClass);
  285
+            initSerializableClone(orig, registry.lookup(superClass), clone, registry.lookup(cloneSuperClass));
286 286
         }
287 287
         if (! serializabilityChecker.isSerializable(objClass)) {
288 288
             if (cloneInfo.hasReadObjectNoData()) {

0 notes on commit 2e276bc

Please sign in to comment.
Something went wrong with that request. Please try again.