Avoid endless loop printing array with MultilineRecursiveToStringStyle

Previous implementation was causing an endless loop by calling
'super.appendDetail' rather than 'super.reflectionAppendArrayDetail'
when it encountered an array type.

Fixes: LANG-1319
This commit is contained in:
duncan 2017-05-19 21:44:28 +01:00
parent 05e18cc5c1
commit 7587431987
3 changed files with 18 additions and 3 deletions

View File

@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="3.6" date="2017-MM-DD" description="TBD">
<action issue="LANG-1319" type="fix" dev="djones">MultilineRecursiveToStringStyle StackOverflowError when object is an array</action>
<action issue="LANG-1325" type="add" dev="kinow" due-to="Arshad Basha">Increase test coverage of ToStringBuilder class to 100%</action>
<action issue="LANG-1307" type="add" dev="pschumacher" due-to="Arshad Basha">Add a method in StringUtils to extract only digits out of input string</action>
<action issue="LANG-1110" type="update" dev="pschumacher" due-to="Bruno P. Kinoshita">Implement HashSetvBitSetTest using JMH</action>

View File

@ -138,11 +138,11 @@ public class MultilineRecursiveToStringStyle extends RecursiveToStringStyle {
protected void reflectionAppendArrayDetail(final StringBuffer buffer, final String fieldName, final Object array) {
spaces += INDENT;
resetIndent();
super.appendDetail(buffer, fieldName, array);
super.reflectionAppendArrayDetail(buffer, fieldName, array);
spaces -= INDENT;
resetIndent();
}
@Override
protected void appendDetail(final StringBuffer buffer, final String fieldName, final long[] array) {
spaces += INDENT;

View File

@ -17,7 +17,7 @@
package org.apache.commons.lang3.builder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
@ -200,6 +200,20 @@ public class MultilineRecursiveToStringStyleTest {
+ "]";
assertEquals(exp, toString(wa));
}
@Test
public void testLANG1319() throws Exception {
final String[] stringArray = {"1", "2"};
final String exp = getClassPrefix(stringArray) + "[" + BR
+ " {" + BR
+ " 1," + BR
+ " 2" + BR
+ " }" + BR
+ "]";
assertEquals(exp, toString(stringArray));
}
private String getClassPrefix(final Object object) {
return object.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(object));