You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "krishna patury (JIRA)" <ji...@apache.org> on 2008/01/04 21:26:34 UTC

[jira] Commented: (LANG-69) [lang] ToStringBuilder throws StackOverflowError when an Object cycle exists

    [ https://issues.apache.org/jira/browse/LANG-69?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12556063#action_12556063 ] 

krishna patury commented on LANG-69:
------------------------------------

Hello,
Has anyone seen the StackOverflowError occur in version2.3 for the use of RefelctionToStringBuilder?

We have the following code using it in our code and it is fine in version 2.0. But when we upgrade to version 2.3 we are seeing a StackOverflowError and do not have any other recursive calls which might cause this..
------------------------------------------------------------------------------------
public String toString() {
    return ReflectionToStringBuilder.toString(this);
}
------------------------------------------------------------------------------------
Any advise would be helpful..Thanks!

> [lang] ToStringBuilder throws StackOverflowError when an Object cycle exists
> ----------------------------------------------------------------------------
>
>                 Key: LANG-69
>                 URL: https://issues.apache.org/jira/browse/LANG-69
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.1
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Maarten Coene
>            Assignee: Gary Gregory
>             Fix For: 2.3
>
>         Attachments: 15938.patch, 36061.patch, LANG-69-refactor.patch, ReflectionToStringBuilder.java.patch, ToStringBuilderTest.java.patch, ToStringStyle.java.patch
>
>
> Hi,
> The ToStringBuilder throws a StackOverflowError if you have a cycle in the
> object graph. For instance, the following toString() method will cause a
> StackOverflowError:
> public class ObjectCycle {
>     Object obj;
>     	
>     public String toString() {
>         return new ToStringBuilder(this).append(obj).toString();
>     }
> }
> public void testObjectCycle() {
>     ObjectCycle a = new ObjectCycle();
>     ObjectCycle b = new ObjectCycle();
>     a.obj = b;
>     b.obj = a;
>     a.toString();  // ouch: StackOverflowError    	
> }
> I'll submit some patches that fixes this problem...
> regards,
> Maarten

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.