[
https://issues.apache.org/jira/browse/LANG-69?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12467980
]
Henri Yandell commented on LANG-69:
-----------------------------------
Still pounding on this issue... Not sure if my refactoring of the registries is
worth it.
Maarten's patch seems to hit the core of the problem. Pull the cyclic
management out of the ReflectionToStringBuilder and down into the ToStringStyle
that ToStringBuilder also shares. This is nice - it means the functionality is
not being split between two classes and for the unit tests that exist it seems
to work - EXCEPT for the ArrayUtils tests where ArrayUtils expects to be able
to pass in an empty array and have it be printed nicely and not as an object
reference.
This is due to the register(object) in appendStart (there are two points of
registration in ToStringStyle, appendStart and appendInternal). Appending the
start data indicator is flagging that the object is being printed (it's not,
it's just the data indicator), so when we then hit append(..) in
ArrayUtils.toString it is failing to iterate into the array because it believes
it has already printed it.
> [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
> Assigned To: 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.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]