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

incorrect hashCode for HashAttributeSet

XMLWordPrintable

    • 2d
    • mantis
    • generic
    • generic
    • Verified



      Name: vtR10009 Date: 07/10/2002


      Specification for the method HashAttributeSet.hashCode() from the
      package javax.print.attribute reads:
      ".. The hash code of an attribute set is defined to be the sum of the hash
      codes of each entry in the AttributeSet."

      But reference implementation does not return the sum.

      This bug causes failure of new JCK test:
        api/javax_print/attribute/HashAttributeSet/index.html#equalsHashCode
        
      To reproduce the bug run the following test with JDK build 1.4.1-rc-b16:
      ------------------------------- test.java --------------------------------
      import java.io.*;
      import javax.print.*;
      import javax.print.attribute.*;
      import javax.print.event.*;
      import javax.print.attribute.standard.*;
      import java.awt.*;

      public class test {

          public static void main(String args[]) {
              boolean failed = false;
              Attribute[] attribArray = {Sides.DUPLEX, MediaName.ISO_A4_TRANSPARENT};
              HashAttributeSet aSet = new HashAttributeSet(attribArray);
              Attribute[] atArr;
              int hashSum = 0;
          
              for (int i = 0; i < attribArray.length; i++) {
                  hashSum += attribArray[i].hashCode();
                  System.err.println(" hashCode:" + attribArray[i].hashCode());
              }

              if (aSet.hashCode() != hashSum) {
                  System.err.println("Set's hashCodes are not equal to the sum: " +
      aSet.hashCode()
                              + " !~ " + hashSum);
                  failed = true;
              }
              
              if( failed ) {
                  System.err.println("test failed");
                  System.exit(1);
              } else {
                  System.out.println("OKAY");
                  System.exit(0);
              }
              
          }
      }

      ---------------------------Logs-------------------------------------------
      novo101:templates$ javac test.java; java -showversion test
      java version "1.4.1-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b16)
      Java HotSpot(TM) Client VM (build 1.4.1-rc-b16, mixed mode)

       hashCode:1
       hashCode:3
      Set's hashCodes are not equal to the sum: 37864664 !~ 4
      test failed
      --------------------------------------------------------------------------
      ======================================================================

            prr Philip Race
            vitcsunw Vitc Vitc (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: