Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1311

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.4, 3.5
    • 3.6
    • lang.reflect.*
    • None
    • Patch

    Description

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

      Specifically, these tests will fail:

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

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

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

      This patch fixes the issue:

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

      Attachments

        Activity

          People

            pascalschumacher Pascal Schumacher
            digulla Aaron Digulla
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified