[jitsi-dev] Overriding equals and hashCode (Was: [jitsi~svn:9968])


#1

Hey Damencho,

I just happened to read the following code in AudioNotifierServiceImpl.java:

private static class AudioClipsKey
{
    ...
    @Override
    public boolean equals(Object o)
    {
        ...
    }
    ...
}

AudioClipsKey key = new AudioClipsKey(uri, playback);
if(audioClips.containsKey(key))

I haven't debugged that code but I can assure you the condition in the if clause above will never evaluate to true because the class AudioClipsKey breaks the general contract about the hashCode method (http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#hashCode()) by overriding equals without overriding hashCode.

Anyway, I wanted to use the case to remind the developers that overriding equals and not overriding hashCode is likely to lead to unexpected behavior.

Regards,
Lyubomir

···

On 12.10.2012, at 13:35, damencho@java.net wrote:

Project: jitsi
Repository: svn
Revision: 9968
Author: damencho
Date: 2012-10-12 10:35:37 UTC
Link:

Log Message:
------------
Adds more options to sound notifications and their config. Sound notifications now can use playback, notification or pc speaker device.

Revisions:
----------
9968

Modified Paths:
---------------
libjitsi/src/org/jitsi/impl/neomedia/notify/AudioNotifierServiceImpl.java