You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Aaron Digulla (JIRA)" <ji...@apache.org> on 2017/02/16 15:51:42 UTC

[jira] [Created] (LANG-1311) TypeUtils.toString() can't handle int[]

Aaron Digulla created LANG-1311:
-----------------------------------

             Summary: TypeUtils.toString() can't handle int[]
                 Key: LANG-1311
                 URL: https://issues.apache.org/jira/browse/LANG-1311
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.reflect.*
    Affects Versions: 3.5, 3.4
            Reporter: Aaron Digulla


TypeUtils.toString() doesn't handle primitive and Object arrays correctly.

Specifically, these tests will fail:

{code}
assertEquals("int[]", TypeUtils.toString(int[].class));
assertEquals("java.lang.Integer[]", TypeUtils.toString(Integer[].class));
{code}

If you declare a field with type {{List<String>[]}}, then you can add this test:

{code}
assertEquals("java.util.List<java.lang.String>[]", TypeUtils.toString(field.getGenericType()));
{code}

This patch fixes the issue:

{code}
    private static String classToString(final Class<?> c) {
// begin patch
        if (c.isArray()) {
            return toString(c.getComponentType()) + "[]";
        }
// end patch 
       
        final StringBuilder buf = new StringBuilder();
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)