Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4641009

java.beans.IndexedPropertyDescriptor.equals works incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs
    • sparc
    • solaris_2.6



      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) {

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

            mdavidsosunw Mark Davidson (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: