StackOverflow with Hibernate3BeanReplicator and Rectangle2D.Double

47 views
Skip to first unread message

ksterg

unread,
Jul 21, 2010, 9:03:18 AM7/21/10
to beanlib
Hello,
the following code:
new Hibernate3BeanReplicator().copy(new Rectangle2D.Double(0, 0,
0, 0));
produces a StackOverflow exception.
Any help?
TIA
Costas

Hanson Char

unread,
Jul 21, 2010, 12:28:33 PM7/21/10
to bea...@googlegroups.com
Yup.  Note Rectangle2D.Double extends from Rectangle2D.  During the replication process, a setter method:

  setFrame(Rectangle2D)

is detected in the target instance, so Beanlib proceeds to retrieve the property from the source instance by invoking the getter method (inherited from java.awt.geom.RectangularShape.java):

  getFrame()

The implementation in RectangularShape.java:

      public Rectangle2D getFrame() {
return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
      }

Here's the problem: a new Rectangle2D.Double instance is created every time the getFrame method is invoked, and Beanlib would try to replicate the new instance, which recursively leads to invoking the getFrame method again on the newly created instances.  Hence the stack overflow.

The solution is provide your own custom transformer to deal with Rectangle2D.Double instead of using the default behavior.  See more details at:
 

Hope this helps.

Hanson

ksterg

unread,
Jul 21, 2010, 1:39:52 PM7/21/10
to beanlib

> The solution is provide your own custom transformer to deal
> with Rectangle2D.Double instead of using the default behavior.  See more
> details at:
>
> http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-doc/b...
>
> Hope this helps.

Thank, this works fine.
Just one more question pls: i have a subclass of Rectangle2D.Double
actually. The solution above works if i set a custom transformer for
my subclass, and not fom the base class (Rectangle2D.Double) which i
extend. Is this correct?
Costas

Hanson Char

unread,
Jul 21, 2010, 2:26:51 PM7/21/10
to bea...@googlegroups.com
Correct

ksterg

unread,
Jul 24, 2010, 6:14:55 AM7/24/10
to beanlib
Thank you! All is good now,
Costas
Reply all
Reply to author
Forward
0 new messages