Bugs item #1344515, was opened at 2005-10-31 23:00
Message generated for change (Comment added) made by sgarlatm
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=700930&aid=1344515&group_id=124910
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 9
Submitted By: Eduard Letifov (techtime)
Assigned to: Nobody/Anonymous (nobody)
Summary: Incorrect handling of empty collections
Initial Comment:
I am using Morph 0.9.1
When I am transform complex object graphs I encounter
a following incorrect behavior: if a source object contains
multiple empty collections such as TreeSet in different
fields, DelegatingTransformer assumes in .hasVisited()
(line 180) that they are equal, and the resulting
(transformed) values can be cached and re-used.
This is incorrect in previous transformation of an empty
collection resulted in an object of a different type (as
dictated by corresponding destination type)
This causes the invocation chain BaseReflector.set ->
ObjectReflector.setImpl -> ReflectionInfo.set ->
MethodHolder.invokeMethod to fail, as argument type to
mutator is incorrect.
Example Test Case:
public class ConversionTest extends TestCase {
public static class A {
}
public static class B {
}
public static class Destination {
A[] field1;
B[] field2;
public A[] getField1() {
return field1;
}
public void setField1(A[] field1) {
this.field1 = field1;
}
public B[] getField2() {
return field2;
}
public void setField2(B[] field2) {
this.field2 = field2;
}
}
public static class Source {
Set field1 = new TreeSet();
Set field2 = new TreeSet();
public Set getField1() {
return field1;
}
public void setField1(Set field1) {
this.field1 = field1;
}
public Set getField2() {
return field2;
}
public void setField2(Set field2) {
this.field2 = field2;
}
}
public void testBug() throws Exception {
Morph.convert(Destination.class, new Source());
}
}
Results in:
net.sf.morph.transform.TransformationException: Error
copying source
com.metservice.ice.breaker.snowie.cytrack.impl.Convers
ionTest$Source@765a16 (class
com.metservice.ice.breaker.snowie.cytrack.impl.Convers
ionTest$Source) to destination
com.metservice.ice.breaker.snowie.cytrack.impl.Convers
ionTest$Destination@16fe0f4 (class
com.metservice.ice.breaker.snowie.cytrack.impl.Convers
ionTest$Destination)
at
net.sf.morph.transform.transformers.BaseTransformer.co
py(BaseTransformer.java:348)
at
net.sf.morph.transform.transformers.DelegatingTransform
er.convertImpl(DelegatingTransformer.java:178)
at
net.sf.morph.transform.transformers.BaseTransformer.co
nvert(BaseTransformer.java:245)
at
net.sf.morph.transform.transformers.BaseTransformer.co
nvert(BaseTransformer.java:257)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at
net.sf.composite.util.DelegatingInvocationHandler.invoke
(DelegatingInvocationHandler.java:53)
at $Proxy7.convert(Unknown Source)
at net.sf.morph.Morph.convert(Morph.java:82)
at
com.metservice.ice.breaker.snowie.cytrack.impl.Convers
ionTest.testBug(ConversionTest.java:180)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at
com.intellij.rt.execution.junit2.JUnitStarter.main
(JUnitStarter.java:31)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at
com.intellij.rt.execution.application.AppMain.main
(AppMain.java:86)
Caused by: net.sf.morph.reflect.ReflectionException:
Unable to set property 'field2' of bean
com.metservice.ice.breaker.snowie.cytrack.impl.Convers
ionTest$Destination@16fe0f4 (class
com.metservice.ice.breaker.snowie.cytrack.impl.Convers
ionTest$Destination) to
[Lcom.metservice.ice.breaker.snowie.cytrack.impl.Conve
rsionTest$A;@a9c09e
at
net.sf.morph.reflect.reflectors.BaseReflector.set
(BaseReflector.java:550)
at
net.sf.morph.reflect.reflectors.DelegatingReflector.setImpl
(DelegatingReflector.java:161)
at
net.sf.morph.reflect.reflectors.BaseReflector.set
(BaseReflector.java:544)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at
net.sf.composite.util.DelegatingInvocationHandler.invoke
(DelegatingInvocationHandler.java:53)
at $Proxy0.set(Unknown Source)
at
net.sf.morph.transform.copiers.BasePropertyNameCopier
.copyProperty(BasePropertyNameCopier.java:120)
at
net.sf.morph.transform.copiers.PropertyNameMatchingC
opier.copyImpl(PropertyNameMatchingCopier.java:86)
at
net.sf.morph.transform.transformers.BaseTransformer.co
py(BaseTransformer.java:342)
... 34 more
Caused by: java.lang.IllegalArgumentException:
argument type mismatch
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at
net.sf.morph.reflect.support.MethodHolder.invokeMutator
(MethodHolder.java:89)
at
net.sf.morph.reflect.support.ReflectionInfo.set
(ReflectionInfo.java:132)
at
net.sf.morph.reflect.reflectors.ObjectReflector.setImpl
(ObjectReflector.java:260)
at
net.sf.morph.reflect.reflectors.BaseReflector.set
(BaseReflector.java:544)
... 45 more
----------------------------------------------------------------------
>Comment By: Matt Sgarlata (sgarlatm)
Date: 2005-12-06 11:30
Message:
Logged In: YES
user_id=1161666
Fixed in Morph 0.9.2 (release is already prepared, and will
be made available soon)
----------------------------------------------------------------------
Comment By: Matt Sgarlata (sgarlatm)
Date: 2005-11-07 10:34
Message:
Logged In: YES
user_id=1161666
I have verified this is a bug. Thanks for the test case!
I'll work on getting this fixed ASAP.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=700930&aid=1344515&group_id=124910
|