JDK-4703629 : Sequencer.SyncMode's equals and hashCode do not work as expected
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2002-06-18
  • Updated: 2002-06-18
  • Resolved: 2002-06-18
Related Reports
Duplicate :  
Description

Name: vtR10009			Date: 06/17/2002


  Specification for the method Sequencer.SyncMode.equals() from the 
package javax.sound.midi reads:
"Determines whether two objects are equal. Returns true if the objects 
are identical 
   Overrides: equals in class Object"
  
  But reference implementation does not override Object.equals() method
and fails for identical instances. The same is true for hashCode()
method.

This bug causes failure of new JCK test:
  api/javax_sound/midi/Sequencer/SyncMode/index.html#equalsHash
  
To reproduce the bug run the following test with JDK build 1.4.1-beta-b14:  
------------------------------- test.java --------------------------------
import javax.sound.midi.*;

public class test{
    public static void main(String args[]) {
        Sequencer.SyncMode sMode1 = new SMode("one");
        Sequencer.SyncMode sMode2 = new SMode("one");

        if (!sMode1.equals(sMode2)) {
            System.err.println("equals() failed: expected true");
        }

        if (sMode1.hashCode() != sMode2.hashCode()) {
            System.err.println("hashCodes are not equal: " + sMode1.hashCode() 
                    + " " + sMode2.hashCode());
        }
    }
}
class SMode extends Sequencer.SyncMode {
    SMode(String name) {
        super(name);
    }
}
---------------------------Logs-------------------------------------------
novo101:templates$ javac test.java; java -showversion test
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

equals() failed: expected true
hashCodes are not equal: 31866429 16795905
--------------------------------------------------------------------------
======================================================================