Uploaded image for project: 'UIMA'
  1. UIMA
  2. UIMA-534

The equals() method in MetaDataObject_impl doesn't compare elements in a Map properly.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.1, 2.2
    • 2.2.1
    • Core Java Framework
    • None

    Description

      In the class org.apache.uima.resource.metadata.impl.MetaDataObject_impl, the equals() method returns immediately with the comparison result of the first Map elements, leaving the rest of the Map's element uncompared.

      Here is the code snippet:
      while (it.hasNext()) {
      Map.Entry entry = (Map.Entry) it.next();
      Object subval1 = ((Map) val1).get(entry.getKey());
      Object subval2 = ((Map) val2).get(entry.getKey());
      if (subval1 == null)

      { if (subval2 != null) return false; }

      else if (subval1 instanceof Object[])

      { if (!(subval2 instanceof Object[])) return false; if (!Arrays.equals((Object[]) subval1, (Object[]) subval2)) return false; line:443 }

      else
      line:444 return subval1.equals(subval2);
      }

      The problem with the code is that the statement line 444 will return the result immediately, causing the while loop to be quit without comparing the rest of elements in the Map.

      To fix this, one could replace line 443 and 444 with the following:
      } else if (!(subval1.equals(subval2))

      { return false; }

      Attachments

        Activity

          People

            alally Adam P. Lally
            danaiw Danai Wiriyayanyongsuk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: