commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 16676] New: - StackOverflow due to ToStringBuilder
Date Sun, 02 Feb 2003 14:20:31 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16676>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16676

StackOverflow due to ToStringBuilder

           Summary: StackOverflow due to ToStringBuilder
           Product: Commons
           Version: 1.0 Alpha
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: keeskuip@technologist.com


The ToStringBuilder doesn't handle relations to other objects
very well. It's very easy to get into an never-ending-loop.
The following code will crash the JVM with a StackOverflowError :

import org.apache.commons.lang.builder.ToStringBuilder;

public class Test1
{
  Test1 test;

  public Test1() {}

  public void setTest(Test1 test)
  {
    this.test = test;
  }

  public String toString()
  {
    return ToStringBuilder.reflectionToString(this);
  }

  public static void main(String[] args)
  {
    Test1 test1;
    Test1 test2;

    test1 = new Test1();
    test2 = new Test1();
    test1.setTest(test2);
    test2.setTest(test1);

    System.out.println(test1.toString());
  }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message