toClass being overridden in ReplicatorTemplate.replicate

3 views
Skip to first unread message

Donnchadh Ó Donnabháin

unread,
Jan 11, 2011, 1:40:53 PM1/11/11
to bea...@googlegroups.com
Hi everyone,

as of revision 405 of ReplicatorTemplate.java,
ReplicatorTemplate.replicate(final Object from, Class<T> toClass)
contains the following

if (unenhanced != from)
toClass = (Class<T>)unenhanced.getClass();

This seems to conflict with the comment for
ReplicatorTemplate.replicate(...) which states:
/**
* Replicate the given from object, recursively if necessary,
* to an instance of the toClass.
*
* Currently a property is replicated if it is an instance
* of Collection, Map, Timestamp, Date, Blob, Hibernate entity,
* JavaBean, or an array.
*/

With the current code toClass is ignored if from is a Hibernate proxy.

Is the above code as intended? Of course I can trivially work around
this by unenhancing the source object before calling replicator.copy
but I'm curious if this is a bug or a necessary part of the bugfix
(duplicate cloning of the same member objects).

Thanks

Donnchadh

Hanson Char

unread,
Jan 12, 2011, 2:09:40 AM1/12/11
to bea...@googlegroups.com
Hi Donnchadh,

Good catch. Can you try to see if the following patch would work
better for you ?

Thanks,
Hanson

--- a/beanlib/src/net/sf/beanlib/provider/replicator/ReplicatorTemplate.java
+++ b/beanlib/src/net/sf/beanlib/provider/replicator/ReplicatorTemplate.java
@@ -79,6 +79,10 @@ public abstract class ReplicatorTemplate


* Replicate the given from object, recursively if necessary,
* to an instance of the toClass.
*

+ * If, however, the from object is an enhanced object and the toClass
+ * is the same as the from object's class, the class of the
un-enhanced object
+ * will be used as the toClass instead of the original toClass.
+ *


* Currently a property is replicated if it is an instance
* of Collection, Map, Timestamp, Date, Blob, Hibernate entity,
* JavaBean, or an array.

@@ -94,8 +98,14 @@ public abstract class ReplicatorTemplate
}
final Object unenhanced = unenhanceObject(from);

- if (unenhanced != from)
- toClass = (Class<T>)unenhanced.getClass();
+ if (unenhanced != from
+ && from.getClass() == toClass)
+ { // The original to-class is an enhanced class:
+ // Use the un-enhanced class instead
+ @SuppressWarnings("unchecked")
+ Class<T> unenhancedClass = (Class<T>)unenhanced.getClass();
+ toClass = unenhancedClass;
+ }

if (containsTargetCloned(from))
{ // already transformed


2011/1/11 Donnchadh Ó Donnabháin <donn...@gmail.com>:

Hanson Char

unread,
Jan 12, 2011, 2:25:27 AM1/12/11
to bea...@googlegroups.com

Donnchadh Ó Donnabháin

unread,
Jan 12, 2011, 3:46:57 AM1/12/11
to bea...@googlegroups.com
That's great, thanks. I'll try that later today.

Donnchadh

Donnchadh Ó Donnabháin

unread,
Jan 12, 2011, 12:00:43 PM1/12/11
to bea...@googlegroups.com
Hi Hanson,

I've tried your fix and it seems to work fine. We will test it further
in tonight's build of our system. I'll let you know if we have any
problem with it but it looks good so far.

Thanks again

Donnchadh

2011/1/12 Donnchadh Ó Donnabháin <donn...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages