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

java.awt.datatransfer.DataFlavor.equals(null) throws Exception

XMLWordPrintable

    • 1.2.2
    • sparc
    • solaris_2.5



      Name: sdC67446 Date: 09/23/98


      The methods equals(DataFlavor df) and equals(String df) of class
      java.awt.datatransfer.DataFlavor throw NullPointerException
      if 'df' == null. More consistent behaviour is to return 'false' for null
      input parameters like equals(Object) does. The behaviour of
      equals(Object) specified in JLS:


      20.1.3 public boolean equals(Object obj)

      This method indicates whether some other object is "equal to" this one.

      The general contract of equals is that it implements an equivalence relation:

            It is reflexive: for any reference value x, x.equals(x) should
              return true.
            It is symmetric: for any reference values x and y, x.equals(y)
              should return true if and only if y.equals(x) returns true.
            It is transitive: for any reference values x, y, and z, if
              x.equals(y) returns true and y.equals(z) returns true, then
              x.equals(z) should return true.
            It is consistent: for any reference values x and y, multiple
              invocations of x.equals(y) consistently return true or
              consistently return false, provided no information used by x
              and y in equals comparisons is modified.
            For any non-null reference value x, x.equals(null) should return false.

      The equals method defined by class Object implements the most discriminating possible equivalence relation on objects;
      that is, for any reference values x and y, ((Object)x).equals(y) returns true if and only if x and y refer to the same
      object.

      The doc says:
      --------------------------------------------------
      public boolean equals(DataFlavor dataFlavor)

            Returns:
                  if the DataFlavors represent the same type.

      public boolean equals(java.lang.String s)

            Returns:
                  if the String (MimeType) is equal

      public boolean equals(java.lang.Object o)

            Returns:
                  if the objects are equal
            Overrides:
                  equals in class java.lang.Object

      The test demonstrating the bug:
      -----------------Test.java------------------------
      import java.awt.datatransfer.*;

      public class Test {

          public static void main(String[] args) {
      DataFlavor df = null;
      try {
      df = new DataFlavor("application/postscript;class=java.awt.datatransfer.DataFlavor");
      } catch (ClassNotFoundException e) {
      System.out.println(e);
      System.exit(1);
      }
      try {
      System.out.println(df.equals((Object)null));
      } catch (Exception e) {
      System.out.println(e);
      }
      try {
      System.out.println(df.equals((String)null));
      } catch (Exception e) {
      System.out.println(e);
      }
      try {
      System.out.println(df.equals((DataFlavor)null));
      } catch (Exception e) {
      System.out.println(e);
      }
          };
      }
      ---------Output-----------------------------------
      false
      java.lang.NullPointerException
      java.lang.NullPointerException
      --------------------------------------------------
      ======================================================================

            prssunw Prs Prs (Inactive)
            sdmitriesunw Sergei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: