Repository: commons-lang
Updated Branches:
  refs/heads/master 05e18cc5c -> 758743198


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

Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/75874319
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/75874319
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/75874319

Branch: refs/heads/master
Commit: 7587431987258e94748d5f2fda1e6ca049a21600
Parents: 05e18cc
Author: duncan <dun...@wortharead.com>
Authored: Fri May 19 21:44:28 2017 +0100
Committer: duncan <dun...@wortharead.com>
Committed: Fri May 19 21:44:28 2017 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                             |  1 +
 .../builder/MultilineRecursiveToStringStyle.java    |  4 ++--
 .../MultilineRecursiveToStringStyleTest.java        | 16 +++++++++++++++-
 3 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/75874319/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6a22895..9f52a9b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -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>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/75874319/src/main/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyle.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyle.java
 
b/src/main/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyle.java
index df82787..7c0375a 100644
--- 
a/src/main/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyle.java
+++ 
b/src/main/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyle.java
@@ -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;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/75874319/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
 
b/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
index daf2881..e3a87f6 100644
--- 
a/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
+++ 
b/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
@@ -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));

Reply via email to