Application of patch from Bugzilla: #33574, by Travis Stevens. Balances a call to appendFieldStart with an appendFieldEnd after appending the field. Test also included.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@156007 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
634f0e9762
commit
308009b9a1
|
@ -631,6 +631,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
||||||
// append a simple Object.toString style string.
|
// append a simple Object.toString style string.
|
||||||
this.getStyle().appendFieldStart(this.getStringBuffer(), fieldName);
|
this.getStyle().appendFieldStart(this.getStringBuffer(), fieldName);
|
||||||
this.appendAsObjectToString(fieldValue);
|
this.appendAsObjectToString(fieldValue);
|
||||||
|
this.getStyle().appendFieldEnd(this.getStringBuffer(), fieldName);
|
||||||
// The recursion out of
|
// The recursion out of
|
||||||
// builder.append(fieldName, fieldValue);
|
// builder.append(fieldName, fieldValue);
|
||||||
// below will append the field
|
// below will append the field
|
||||||
|
|
|
@ -487,6 +487,24 @@ public class ToStringBuilderTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
* Test an Object pointing to itself, the simplest test.
|
||||||
*
|
*
|
||||||
|
@ -511,6 +529,20 @@ public class ToStringBuilderTest extends TestCase {
|
||||||
assertEquals(this.toBaseString(test) + "[typeIsSelf=" + this.toBaseString(test) + "]", test.toString());
|
assertEquals(this.toBaseString(test) + "[typeIsSelf=" + this.toBaseString(test) + "]", test.toString());
|
||||||
this.validateEmptyReflectionRegistry();
|
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.
|
* Test Objects pointing to each other.
|
||||||
|
|
Loading…
Reference in New Issue