JDK-4663506 : RFE: override equals() method in info classes
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.1,1.4.2,5.0,5.0u4,6
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic,linux,windows_2000
  • CPU: generic,x86
  • Submitted: 2002-04-05
  • Updated: 2017-05-19
  • Resolved: 2005-12-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
Name: vtR10009			Date: 04/05/2002


  Specification for the method MidiDevice.Info.equals() from the package
javax.sound.midi reads:
"Reports 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/MidiDevice/index.html#TypeCtor
  
To reproduce the bug run the following test with JDK build 1.4.1-beta-b07:
------------------------------- test.java --------------------------------
import javax.sound.midi.*;
import java.io.*;


public class test {

    public static void main(String args[]) {
        boolean failed = false;
        String name = "name";
        String vendor = "vendor";
        String descr = "description";
        String ver = "version";
        String sameName = "name";
        MidiDevice.Info dInfo1 = new DevInfo(name, vendor, descr, ver);
        MidiDevice.Info dInfo2 = new DevInfo(name, vendor, descr, ver);

        if (!dInfo1.equals(dInfo2)) {
            System.out.println("These devices must be equal!");
            System.out.println("Device:" + dInfo1);
            System.out.println("Device:" + dInfo2);
            failed = true;
        }    
        dInfo2 = new DevInfo(sameName, vendor, descr, ver);
        if (!dInfo1.equals(dInfo2)) {
            System.out.println("These devices must be equal too!");
            System.out.println("Device:" + dInfo1);
            System.out.println("Device:" + dInfo2);
            failed = true;
        }    
    
        if( failed == true ) {
            System.out.println("Test failed!");
        } else {
            System.out.println("OK.");
        }
        System.exit(0);
    }
}

class DevInfo extends MidiDevice.Info {
    DevInfo(String n,String v1,String d,String v2) {
    super(n,v1,d,v2);
    }
}
---------------------------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-b07)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b07, mixed mode)

These devices must be equal!
Device:name
Device:name
These devices must be equal too!
Device:name
Device:name
Test failed!

--------------------------------------------------------------------------
======================================================================

###@###.### 2002-09-25
	This RFE applies to the following classes:
AudioFileFormat
AudioFileFormat.Type
AudioFormat
AudioFormat.Encoding
Control.Type
DataLine.Info
Line.Info
LineEvent.Type
Mixer.Info
Port.Info
ReverbType
Instrument
MetaMessage
MidiDevice.Info
MidiEvent
MidiFileFormat
MidiMessage
Patch
Sequencer.SyncMode
ShortMessage
SoundbankResource
SysexMessage

Comments
EVALUATION It liooks like JCK test is incorrect. Specification for MidiDevice.Info.equals(obj) reads: Reports whether two objects are equal. Returns true if the objects are identical. param obj - the reference object with which to compare this object return true if this object is the same as the obj argument; false otherwise It does mention that these methods, equals() and hashcode(), are overwritten, but it does not explicitly say what their behavior is (i.e. if equals should return true if the objects have the same <list of> values, or if they are the same object). Main destination of Info object is identify it's parent object (in the case MidiDevice). Two deffirent MidiDevices may have the same name, vendor, decription & version, but they shouldn't be equal. The goal of overriding equals() method may be it's finalization (but it's unclear for me what for it it).
01-12-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
14-06-2004

PUBLIC COMMENTS RFE: override equals() method in info classes
10-06-2004

EVALUATION ###@###.### 2002-04-22 This is major problem with all the Info/Type/Encoding classes: the equals() method should compare the strings/format, but not the object reference. Not sure what is the best way to solve this problem. 2 basic alternatives: 1 - add a method to all those classes like boolean matches(...) 2 - change semantics of equals(). May break external apps, will make it necessary to redesign major parts of the internal Java Sound implementation. ###@###.### 2002-06-18 Also affected: Sequencer.SyncMode and their hash codes (see 4703629 - closed as duplicate). Will contact the original authors of the API to find out why equals() is overriden to finalize it, but still using Object.equals() semantics. ###@###.### 2002-09-25 Changed to RFE with new synopsis (old synopsis: "MidiDevice.Info equality"). ###@###.### 2003-04-21 Another new bug was closed as a duplicate of this: 4850973: MidiMesssage and subclasses: .equals() not implemented. ###@###.### 2003-09-19 Due to time constraints for tiger, AudioFormat.Encoding and AudioFileFormat.Type were moved to a new RFE: 4925483: equals() should compare string in Encoding and Type ###@###.### 2003-10-01 Committing this bug to dragon.
01-10-2003