Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3789

Comparing maps in GenericData is wrong for certain combinations and fails for empty maps

    XMLWordPrintableJSON

Details

    Description

      The rewritten map comparison implementation in GenericData (AVRO-2943 according to the commit message) throws a NoSuchElementException when used to compare empty maps. Partial stacktrace:

      Caused by: java.util.NoSuchElementException
      	at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1513)
      	at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1534)
      	at org.apache.avro.generic.GenericData.compareMaps(GenericData.java:1163)
      	at org.apache.avro.generic.GenericData.compare(GenericData.java:1250)
      	at org.apache.avro.specific.SpecificData.compare(SpecificData.java:476)
      	at org.apache.avro.generic.GenericData.compare(GenericData.java:1229)
      	at org.apache.avro.specific.SpecificData.compare(SpecificData.java:476)
      	at org.apache.avro.specific.SpecificRecordBase.equals(SpecificRecordBase.java:88)
      	at scala.runtime.BoxesRunTime.equals2(BoxesRunTime.java:133)
      	at scala.runtime.BoxesRunTime.equals(BoxesRunTime.java:119)
      	at org.scalactic.DefaultEquality$.areEqualComparingArraysStructurally(DefaultEquality.scala:70)
      	at org.scalactic.DefaultEquality.areEqual(DefaultEquality.scala:37)
      	at org.mockito.package$$anon$2.areEqual(mockito.scala:614)
      	at org.scalactic.TripleEqualsSupport$Equalizer.$eq$eq$eq(TripleEqualsSupport.scala:117)
      	at org.mockito.matchers.EqTo.matches(EqTo.scala:11)
      ... 
      

       


      Also, the check in line 1170 that's intended to shortcircuit for maps of different sizes is incorrect. Because of this, maps will incorrectly compare equal when:

      • their sizes are different
      • one is a superset of the other map

      Attachments

        Issue Links

          Activity

            People

              fkrull-neuland Felix Krull
              fkrull-neuland Felix Krull
              Votes:
              1 Vote for this issue
              Watchers:
              4 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