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

ToStringBuilder behavior for collections changed with 3.11

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.11
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Description

      The fix in LANG-1542 (git commit 1dddec8) had side effects and did not just affect json styles, but DEFAULT_STYLE, SHORT_PREFIX_STYLE, and possibly others as well.

      Also, collections are now treated differently when empty:
      Square brackets for empty list vs. curly brackets for non-empty lists.

      Test case

      new ToStringBuilder(new Object(), ToStringStyle.SHORT_PREFIX_STYLE)
              .append("foo0", Collections.emptyList())
              .append("foo1", Collections.singleton("1"))
              .append("foo2", Arrays.asList("1", "2"))
              .build();
      

      SHORT_PREFIX_STYLE

      Result for version 3.11:

      Object[foo0=[],foo1={1},foo2={1,2}]
      

      Expected (also as-is for 3.10)

      Object[foo0=[],foo1=[1],foo2=[1, 2]]
      

      DEFAULT_STYLE

      Result for version 3.11

      java.lang.Object@7960847b[foo0=[],foo1={1},foo2={1,2}]
      

      Expected (also as-is for 3.10)

      java.lang.Object@7960847b[foo0=[],foo1=[1],foo2=[1, 2]]
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              amphied Michael F
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

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