JDK-4641009 : java.beans.IndexedPropertyDescriptor.equals works incorrectly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2002-02-21
  • Updated: 2003-03-17
  • Resolved: 2003-03-17
Related Reports
Duplicate :  
Description

Name: dsR10051			Date: 02/21/2002


Method of class java.beans.IndexedPropertyDescriptor
public boolean equals(Object obj)
works incorrect. It is not symmetric in case of comparing 
IndexedPropertyDescriptor and PropertyDescriptor objects with the same
propertyName.

Here is minimized test:

--- IndexedPropertyDescriptorTest01.java ---
import java.beans.*;

public class IndexedPropertyDescriptorTest01 {

    public static void main(String[] args) {
        IndexedPropertyDescriptor pd = null;
        PropertyDescriptor obj = null;
        try {
            pd = new IndexedPropertyDescriptor("child", Wombat.class);
            obj = new PropertyDescriptor("child", Wombat.class);
        } catch (IntrospectionException ie) {
            System.out.println("Unexpected IntrospectionException");
            return;
        }
        if (pd.equals(obj) != obj.equals(pd)) {
            System.out.println("Symmetric check failed");
            return;
        }
        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;
    }

}
-------------
Here is 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)
bash-2.03$ /set/java/jdk1.4.1/solaris/bin/java IndexedPropertyDescriptorTest01 
Symmetric check failed
-------------

equals(Object) method should be symmetric due to the general contract of 
equivalence relation that is described in javadoc for java.lang.Object.equals:
"   /**
     * Indicates whether some other object is "equal to" this one.
     * <p>
     * The <code>equals</code> method implements an equivalence relation: 
     * <ul>
... skipped 
     * <li>It is <i>symmetric</i>: for any reference values <code>x</code> and 
     *     <code>y</code>, <code>x.equals(y)</code> should return 
     *     <code>true</code> if and only if <code>y.equals(x)</code> returns 
     *     <code>true</code>. 
... skipped 
     */
    public boolean equals(Object obj) {

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

Comments
EVALUATION The unfortunate nature of the relationship between PropertyDescriptor and IndexedPropertyDescriptor enforce the assymetric relationshp. On one hand, an IndexedPropertyDescriptor that has been referenced as a PropertyDescriptor will use a set of accessor methods to get at the properties: getReadMethod(), getWriteMethod(), getPropertyType(). However, if that descriptor is cast to an IndexedPropertyDescriptor then you must use a different set of accessors to get at the properties: getIndexedPropertyType(), getIndexedReadMethod(), getIndexedWriteMethod(). Not sure how to resolve this. This is one of the fundamental flaws in the architecture for IndexedPropertyDescriptors. The saving grace is that the Introspector would treat the Wombat class property "child" as an IndexedProperty. The comparison and test is valid but it's largely academic. ###@###.### 2002-02-22 This is another example of the ambiguity that arises when a PD is cast to an IPD. I'm going to close this out as a duplicate of 4619536. ###@###.### 2003-03-17 This bug has been closed as duplicate of #4619536. #4619536 has INT status now, but minimal test from this bug is still failed. So, this bug should be reopen. ###@###.### 2003-11-28
28-11-2003