Repository: commons-lang
Updated Branches:
  refs/heads/master 30c85ad05 -> 1661e5519


LANG-1311: TypeUtils.toString() doesn't handle primitive and Object arrays 
correctly

apply patch by Aaron Digulla


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

Branch: refs/heads/master
Commit: 1661e5519c4836a5a940b13b7797263443156fc9
Parents: 30c85ad
Author: pascalschumacher <pascalschumac...@gmx.net>
Authored: Fri Feb 17 18:32:32 2017 +0100
Committer: pascalschumacher <pascalschumac...@gmx.net>
Committed: Fri Feb 17 18:32:32 2017 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                                   |  3 ++-
 .../java/org/apache/commons/lang3/reflect/TypeUtils.java  |  4 ++++
 .../org/apache/commons/lang3/reflect/TypeUtilsTest.java   | 10 ++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1661e551/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 330a0b7..b023f95 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,7 +45,7 @@ The <action> type attribute can be add,update,fix,remove.
   </properties>
   <body>
 
-  <release version="3.6" date="2016-MM-DD" description="TBD">
+  <release version="3.6" date="2017-MM-DD" description="TBD">
     <action issue="LANG-1299" type="add" dev="djones">Add method for 
converting string to an array of code points</action>
     <action issue="LANG-1286" type="fix" dev="djones">RandomStringUtils random 
method can overflow and return characters outside of specified range</action>
     <action issue="LANG-660" type="add" dev="djones">Add methods to insert 
arrays into arrays at an index</action>
@@ -75,6 +75,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action issue="LANG-1143" type="update" dev="pschumacher" 
due-to="sebb">StringUtils should use toXxxxCase(int) rather than 
toXxxxCase(char)</action>
     <action issue="LANG-1297" type="update" dev="ggregory">Add 
SystemUtils.getHostName() API.</action>
     <action issue="LANG-1301" type="update" dev="pschumacher" due-to="Karl 
Heinz Marbaise">Moving apache-rat-plugin configuration into 
pluginManagement</action>
+    <action issue="LANG-1311" type="fix" dev="pschumacher" due-to="Aaron 
Digulla">TypeUtils.toString() doesn't handle primitive and Object arrays 
correctly</action>
   </release>
 
   <release version="3.5" date="2016-10-13" description="New features including 
Java 9 detection">

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1661e551/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java 
b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
index da448c9..8db6ca4 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
@@ -1742,6 +1742,10 @@ public class TypeUtils {
      * @since 3.2
      */
     private static String classToString(final Class<?> c) {
+        if (c.isArray()) {
+            return toString(c.getComponentType()) + "[]";
+        }
+
         final StringBuilder buf = new StringBuilder();
 
         if (c.getEnclosingClass() != null) {

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1661e551/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
index b01bd0f..afc5b74 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
@@ -101,6 +101,8 @@ public class TypeUtilsTest<B> {
 
     public static URI uri;
 
+    public static List<String>[] stringListArray;
+
     public void dummyMethod(final List list0, final List<Object> list1, final 
List<?> list2,
             final List<? super Object> list3, final List<String> list4, final 
List<? extends String> list5,
             final List<? super String> list6, final List[] list7, final 
List<Object>[] list8, final List<?>[] list9,
@@ -744,6 +746,14 @@ public class TypeUtilsTest<B> {
     }
 
     @Test
+    public void testToStringLang1311() {
+        Assert.assertEquals("int[]", TypeUtils.toString(int[].class));
+        Assert.assertEquals("java.lang.Integer[]", 
TypeUtils.toString(Integer[].class));
+        Field stringListField = FieldUtils.getDeclaredField(getClass(), 
"stringListArray");
+        Assert.assertEquals("java.util.List<java.lang.String>[]", 
TypeUtils.toString(stringListField.getGenericType()));
+    }
+
+    @Test
     public void testToLongString() {
         Assert.assertEquals(getClass().getName() + ":B", 
TypeUtils.toLongString(getClass().getTypeParameters()[0]));
     }

Reply via email to