You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2005/03/03 06:00:46 UTC
svn commit: r156007 - in jakarta/commons/proper/lang/trunk/src:
java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java
test/org/apache/commons/lang/builder/ToStringBuilderTest.java
Author: bayard
Date: Wed Mar 2 21:00:44 2005
New Revision: 156007
URL: http://svn.apache.org/viewcvs?view=rev&rev=156007
Log:
Application of patch from Bugzilla: #33574, by Travis Stevens. Balances a call to appendFieldStart with an appendFieldEnd after appending the field. Test also included.
Modified:
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java?view=diff&r1=156006&r2=156007
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java Wed Mar 2 21:00:44 2005
@@ -631,6 +631,7 @@
// append a simple Object.toString style string.
this.getStyle().appendFieldStart(this.getStringBuffer(), fieldName);
this.appendAsObjectToString(fieldValue);
+ this.getStyle().appendFieldEnd(this.getStringBuffer(), fieldName);
// The recursion out of
// builder.append(fieldName, fieldValue);
// below will append the field
Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java?view=diff&r1=156006&r2=156007
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java (original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java Wed Mar 2 21:00:44 2005
@@ -487,6 +487,24 @@
}
}
+ private static class SelfInstanceTwoVarsReflectionTestFixture {
+ private SelfInstanceTwoVarsReflectionTestFixture typeIsSelf;
+ private String otherType = "The Other Type";
+
+ public SelfInstanceTwoVarsReflectionTestFixture() {
+ this.typeIsSelf = this;
+ }
+
+ public String getOtherType(){
+ return this.otherType;
+ }
+
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this);
+ }
+ }
+
+
/**
* Test an Object pointing to itself, the simplest test.
*
@@ -511,6 +529,20 @@
assertEquals(this.toBaseString(test) + "[typeIsSelf=" + this.toBaseString(test) + "]", test.toString());
this.validateEmptyReflectionRegistry();
}
+
+ /**
+ * Test a class that defines an ivar pointing to itself. This test was
+ * created to show that handling cyclical object resulted in a missing endFieldSeparator call.
+ *
+ * @throws Exception
+ */
+ public void testSelfInstanceTwoVarsReflectionObjectCycle() throws Exception {
+ SelfInstanceTwoVarsReflectionTestFixture test = new SelfInstanceTwoVarsReflectionTestFixture();
+ assertTrue(ReflectionToStringBuilder.getRegistry().isEmpty());
+ assertEquals(this.toBaseString(test) + "[typeIsSelf=" + this.toBaseString(test) + ",otherType=" + test.getOtherType().toString() + "]", test.toString());
+ this.validateEmptyReflectionRegistry();
+ }
+
/**
* Test Objects pointing to each other.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org