Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-848

testToString() is non-deterministic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Invalid
    • 4.4
    • None
    • Map

    Description

      Problem

      The testToString() function that is being implemented by multiple classes and is nondeterministic. 

      The following classes implement this function-

      • org.apache.commons.collections4.multimap.TransformedMultiValuedMapTest.testToString
      • org.apache.commons.collections4.multimap.HashSetValuedHashMapTest.testToString
      • org.apache.commons.collections4.multimap.ArrayListValuedHashMapTest.testToString

      Fix

      This test asserts map.toString() is equal to a hardcoded combination of strings namely -

      {A=[X, Y, Z], B=[U, V, W]}
      {B=[U, V, W], A=[X, Y, Z]}
      

      where the map is of the type MultiValuedMap. Here the map.toString() might return _

      {B=[U, V, W], A=[X, Y, Z]}

      _ for the LHS and {{A=[X, Y, Z], B=[U, V, W]} for the RHS which can let the test fail at times.

      The toString() function is not inherently flaky and thus is not the root cause of the issue. The initialization of MultiValuedMap with makeObject() is what causes the issue as this can change the order of the keys.

      PR: https://github.com/apache/commons-collections/pull/426

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ar80 Anirudh Ragavender
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: