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

methods TextFlavor.equals(null) throw NPE

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: sdC67446 Date: 05/31/99


      The two methods of class java.awt.datatransfer.TextFlavor
          equals(String mimeString) and
          equals(DataFlavor that)
      throw NullPointerException for null input parameter.
      Should return false;

      The JLS says:
      -------------------------------------------------
      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 test demonstrating the bug:
      -----------------Test.java------------------------
      import java.awt.datatransfer.*;

      public class Test {

          public static void main(String[] args) {
              TextFlavor tf;
              try {
                  tf = new TextFlavor("text/plain");
                  tf.equals((String)null);
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              } catch (NullPointerException e1) {
                  e1.printStackTrace();
              }
              try {
                  tf = new TextFlavor("text/plain");
                  tf.equals((DataFlavor)null);
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              } catch (NullPointerException e1) {
                  e1.printStackTrace();
              }
          };
      }
      ---------Output-----------------------------------
      java.lang.NullPointerException
              at java.awt.datatransfer.MimeType.parse(MimeType.java, Compiled Code)
              at java.awt.datatransfer.MimeType.<init>(MimeType.java, Compiled Code)
              at java.awt.datatransfer.TextFlavor.equals(TextFlavor.java, Compiled Code)
              at Test.main(Test.java, Compiled Code)
      java.lang.NullPointerException
              at java.awt.datatransfer.TextFlavor.equals(TextFlavor.java, Compiled Code)
              at Test.main(Test.java, Compiled Code)
      --------------------------------------------------
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            ehawkessunw Eric Hawkes (Inactive)
            Reporter:
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: