JDK-4641061 : PropertyDescriptor.hashCode() call produces incorrect result
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2002-02-21
  • Updated: 2002-02-22
  • Resolved: 2002-02-22
Related Reports
Duplicate :  
Description

Name: dsR10051			Date: 02/21/2002


Method hashCode() is not declared in classes 
java.beans.PropertyDescriptor and java.beans.IndexedPropertyDescriptor
It violates the general contract of this method that declares
the equality of hash codes if objects are equals.
This contract is explained in javadoc for java.lang.Object.hashCode():
"
    /**
     * Returns a hash code value for the object. This method is 
     * supported for the benefit of hashtables such as those provided by 
     * <code>java.util.Hashtable</code>. 
     * <p>
     * The general contract of <code>hashCode</code> is: 
     * <ul>
... skipped     
     * <li>If two objects are equal according to the <tt>equals(Object)</tt>
     *     method, then calling the <code>hashCode</code> method on each of 
     *     the two objects must produce the same integer result. 
... skipped     
     */
    public native int hashCode();
"

Here is minimized test:

--- IndexedPropertyDescriptorTest02.java ---

import java.beans.*;

public class IndexedPropertyDescriptorTest02 {

    public static void main(String[] args) {
        PropertyDescriptor pd = null;
        PropertyDescriptor obj = null;
        try {
            pd = new IndexedPropertyDescriptor("child", Wombat.class);
            obj = new IndexedPropertyDescriptor("child", Wombat.class);
        } catch (IntrospectionException ie) {
            System.out.println("Unexpected IntrospectionException");
            return;
        }
        if (pd.equals(obj) && (pd.hashCode() != obj.hashCode())) {
            System.out.println("IndexedPropertyDescriptor objects are equals, but their hash codes are different");
        } else {
            System.out.println("OKAY");
        }
        try {
            pd = new PropertyDescriptor("child", Wombat.class);
            obj = new PropertyDescriptor("child", Wombat.class);
        } catch (IntrospectionException ie) {
            System.out.println("Unexpected IntrospectionException");
            return;
        }
        if (pd.equals(obj) && (pd.hashCode() != obj.hashCode())) {
            System.out.println("PropertyDescriptor objects are equals, but their hash codes are different");
        } else {
            System.out.println("OKAY");
        }
        
    }

}

--- Wombat.java ---
public class Wombat {

    Wombat[] child = new Wombat[10];

    public Wombat getChild(int index) {
	return child[index];
    }

    public void setChild(int index, Wombat w) {
	child[index] = w;
    }

    public Wombat[] getChild() {
	return child;
    }

    public void setChild(Wombat[] child) {
	this.child = child;
    }

}

--- Output ---

% /set/java/jdk1.4.1/solaris/bin/java -version
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b02)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b02, mixed mode)
% /set/java/jdk1.4.1/solaris/bin/java IndexedPropertyDescriptorTest02
IndexedPropertyDescriptor objects are equals, but their hash codes are different
PropertyDescriptor objects are equals, but their hash codes are different

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

Comments
EVALUATION Duplicate of 4634390. Should use this test case. ###@###.### 2002-02-22
22-02-2002