hk2
  1. hk2
  2. HK2-93

Inconsistent behavior of MultiMap methods

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.*
    • Fix Version/s: 2.1.*
    • Component/s: None
    • Labels:
      None

      Description

      Since MultiMap is used in many places we are going to continue to support it. So I started to unit test it. And in doing so, I found inconsistent behaviors for the API.

      The biggest problem is with the definition of the behavior when given an empty list. Consider this:
      MultiMap<String, String> mm = new MultiMap<String, String>();

      int size = mm.size(); // Will return zero
      mm.set(KEY1, new LinkedList<String>());

      size = mm.size(); // Will return 1
      boolean containsKey = mm.containsKey(KEY1); // Returns false!

      The real question at this point is which is correct, the "containsKey" or the "size" ?

      This same problem occurs in other manners, for example if you remove every value in a key the "containsKey" for that key will return false but the "size" method will still account for the key with the empty list.

        Activity

        Hide
        jwells added a comment -

        As an interesting not, the "get" for any key will return an empty list (as opposed to null) whether or not the key is in the map or not. To me, this fact argues that empty lists should NOT be included in the size, and, not "truly" added in the "set" call.

        Show
        jwells added a comment - As an interesting not, the "get" for any key will return an empty list (as opposed to null) whether or not the key is in the map or not. To me, this fact argues that empty lists should NOT be included in the size, and, not "truly" added in the "set" call.
        Hide
        jwells added a comment -

        Another thing currently wrong with MultiMap is that the hashCode and equals do not meet Java standards. You can have two maps for which "equals" returns true but for which hashCode returns different numbers.

        Show
        jwells added a comment - Another thing currently wrong with MultiMap is that the hashCode and equals do not meet Java standards. You can have two maps for which "equals" returns true but for which hashCode returns different numbers.
        Hide
        jwells added a comment -

        Tests added for MultiMap and incongruous behaviour made... uh... congruous. Basically, empty value lists will not show up as having an associated key.

        Show
        jwells added a comment - Tests added for MultiMap and incongruous behaviour made... uh... congruous. Basically, empty value lists will not show up as having an associated key.

          People

          • Assignee:
            jwells
            Reporter:
            jwells
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: