Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-30075

ArrayIndexType doesn't implement hashCode correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.4.4, 3.0.0
    • 3.0.0
    • Spark Core
    • None

    Description

      https://github.com/apache/spark/blob/master/common/kvstore/src/test/java/org/apache/spark/util/kvstore/ArrayKeyIndexType.java

      public class ArrayKeyIndexType {
        @KVIndex
        public int[] key;
      
        @KVIndex("id")
        public String[] id;  
      
        @Override
        public boolean equals(Object o) {
          if (o instanceof ArrayKeyIndexType) {
            ArrayKeyIndexType other = (ArrayKeyIndexType) o;
            return Arrays.equals(key, other.key) && Arrays.equals(id, other.id);
          }
          return false;
        }
      
        @Override
        public int hashCode() {
          return key.hashCode();
        }
      } 

      Here hashCode() simply calls key.hashCode() which won't work as our intention - as the implementation would be Object.hashCode(). We need to call Array.hashCode(key) instead.

      Attachments

        Issue Links

          Activity

            People

              kabhwan Jungtaek Lim
              kabhwan Jungtaek Lim
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: