Hadoop Common
  1. Hadoop Common
  2. HADOOP-7153

MapWritable violates contract of Map interface for equals() and hashCode()

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.21.0
    • Fix Version/s: 0.23.0
    • Component/s: io
    • Labels:
      None
    • Hadoop Flags:
      Incompatible change, Reviewed
    • Release Note:
      MapWritable now implements equals() and hashCode() based on the map contents rather than object identity in order to correctly implement the Map interface.

      Description

      o.a.h.io.MapWritable implements the java.util.Map interface, however it does not define an implementation of the equals() or hashCode() methods; instead the default implementations in java.lang.Object are used.

      This violates the contract of the Map interface which defines different behaviour for equals() and hashCode() than Object does. More information here: http://download.oracle.com/javase/6/docs/api/java/util/Map.html#equals(java.lang.Object)

      The practical consequence is that MapWritables containing equal entries cannot be compared properly. We were bitten by this when trying to write an MRUnit test for a Mapper that outputs MapWritables; the MRUnit driver cannot test the equality of the expected and actual MapWritable objects.

      1. 7153-mapwritable-equality.combined.diff
        2 kB
        Nicholas Telford
      2. 7153-mapwritable-equality.diff
        0.9 kB
        Nicholas Telford
      3. 7153-mapwritable-equality-test.diff
        1.0 kB
        Nicholas Telford

        Issue Links

          Activity

          Nicholas Telford created issue -
          Nicholas Telford made changes -
          Field Original Value New Value
          Status Open [ 1 ] Patch Available [ 10002 ]
          Hadoop Flags [Incompatible change]
          Nicholas Telford made changes -
          Attachment 7153-mapwritable-equality.diff [ 12471728 ]
          Attachment 7153-mapwritable-equality-test.diff [ 12471729 ]
          Nicholas Telford made changes -
          Attachment 7153-mapwritable-equality.combined.diff [ 12471822 ]
          Todd Lipcon made changes -
          Assignee Nicholas Telford [ nicktelford ]
          Todd Lipcon made changes -
          Status Patch Available [ 10002 ] Resolved [ 5 ]
          Hadoop Flags [Incompatible change] [Incompatible change, Reviewed]
          Release Note MapWritable now implements equals() and hashCode() based on the map contents rather than object identity in order to correctly implement the Map interface.
          Fix Version/s 0.23.0 [ 12315569 ]
          Resolution Fixed [ 1 ]
          Arun C Murthy made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Tom White made changes -
          Link This issue relates to HADOOP-9124 [ HADOOP-9124 ]

            People

            • Assignee:
              Nicholas Telford
              Reporter:
              Nicholas Telford
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development