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

java.beans.IndexedPropertyDescriptor.equals works incorrectly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

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

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: