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/20 20:20:44 UTC

[jira] [Commented] (LANG-1311) TypeUtils.toString() doesn't handle primitive and Object arrays correctly

    [ https://issues.apache.org/jira/browse/LANG-1311?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15875025#comment-15875025 ] 

Aaron Digulla commented on LANG-1311:
-------------------------------------

Thanks.

The generics list worked but I didn't see a unit test for a mix of generics and arrays, so I added one for good measure.

> TypeUtils.toString() doesn't handle primitive and Object arrays correctly
> -------------------------------------------------------------------------
>
>                 Key: LANG-1311
>                 URL: https://issues.apache.org/jira/browse/LANG-1311
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.reflect.*
>    Affects Versions: 3.4, 3.5
>            Reporter: Aaron Digulla
>            Assignee: Pascal Schumacher
>            Priority: Minor
>             Fix For: 3.6
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> 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)