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

DataFlavor.toString() does not know its specification

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: sdC67446 Date: 06/30/99


      The method
          public String toString()
      does not return the String specified in documentation:
        getClass().getName() + '@' + Integer.toHexString(hashCode())

      Also method toString() throws unspecified NullPointerException if
      instance has been created with DataFlavor();

      The doc says:
      --------------------------------------------------
      public String toString()

            Description copied from class: Object
            Returns a string representation of the object. In general, the
            toString method returns a string that "textually represents"
            this object. The result should be a concise but informative
            representation that is easy for a person to read. It is
            recommendedthat all subclasses override this method.

            The toString method for class Object returns a string consisting
            of the name of the class of which the object is an instance, the
            at-sign character `@', and the unsigned hexadecimal
            representation of the hash code of the object. In other words,
            this method returns a string equal to the value of:

            getClass().getName() + '@' + Integer.toHexString(hashCode())
                   

            Overrides:
                  toString in class Object
            Tags copied from class: Object
            Returns:
                  a string representation of the object.
      ---------Test.java--------------------------------
      import java.awt.datatransfer.*;

      public class Test {
          public static void main(String[] args) {
              try {
                  DataFlavor df = new DataFlavor("text/plain");
                  String expected = df.getClass().getName()+"@"+
                                    Integer.toHexString(df.hashCode());
                  System.out.println(df.toString());
                  System.out.println(expected);
                  System.out.println(expected.equals(df.toString()));
                  df = new DataFlavor();
              } catch (ClassNotFoundException e) {
                  System.out.println(e);
              }
              try {
                  DataFlavor df = new DataFlavor();
                  System.out.println(df.toString());
              } catch (NullPointerException e) {
                  System.out.println("-- "+e);
              }
          }
      }
      ---------Output-----------------------------------
      java.awt.datatransfer.DataFlavor[mimetype=[text/plain; class=java.io.InputStream]]
      java.awt.datatransfer.DataFlavor@ff23f224
      false
      -- java.lang.NullPointerException
      --------------------------------------------------
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            prssunw Prs Prs (Inactive)
            Reporter:
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: