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

java.util.jar.Manifest violates equals/hashCode contract

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.2.0
    • tools
    • jar
    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: mgC56079 Date: 08/17/98



      JLS 1.0 item 20.1.4 says:

          If two objects are equal according to the equals method (20.1.3),
          then calling the hashCode method on each of the two objects must
          produce the same integer result.

      This is not true for java.util.jar.Manifest objects.
      Manifest class should override both equals() and hashCode() methods.

      Here is the test demonstrating the bug (should print 'true' in both cases):
      -----------------ManifestTest.java------------------------
      import java.util.jar.*;
      import java.io.*;

      public class ManifestTest {

        public static void main(String args[]) {
          Manifest manifest1=new Manifest();
          Manifest manifest2=(Manifest)(manifest1.clone());
          System.out.println(manifest1.equals(manifest2));
          System.out.println(manifest1.hashCode()==manifest2.hashCode());

        }

      }
      -----------------sample run (jdk1.2fcsF)------------------------
      % java ManifestTest
      true
      false


      ======================================================================

            dconnellsunw David Connelly (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: