Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8218584

inconsistency between the two remove() methods of Collections.emptyMap()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      Colleague Tobias Thierer reports:

      ====

      Both the one- and the two-argument version of Map.remove() are specified to throw UnsupportedOperationException "if the remove operation is not supported by this map".

      Collections.emptyMap()'s behavior is inconsistent with this specification:

       * Collections.EmptyMap.remove(Object) is a no-op, implying that emptyMap() supports the remove operation.
       * Collections.EmptyMap.remove(Object, Object) throws UOE, implying that emptyMap() does not support the remove operation.

      If we wanted to be consistent, then, depending on whether or not EmptyMap should be considered to support remove (kind of an arbitrary choice):

       (a) EmptyMap should override remove(Object) to throw UOE, or else
       (b) the EmptyMap.remove(Object, Object) override should be dropped

      Since remove(Object) has been around for longer than remove(Object, Object), Option (b) might be less likely to cause backwards compatibility problems.

        Attachments

          Activity

            People

            • Assignee:
              smarks Stuart Marks
              Reporter:
              martin Martin Buchholz
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: