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

javadoc inconsistency in DataFlavor's ctors

XMLWordPrintable

    • beta2
    • sparc
    • solaris_7



      Name: sdR10048 Date: 12/26/2000


      The javadoc for java.awt.datatransfer.DataFlavor says:

      =(1)==============================================================
      public DataFlavor(String mimeType,
                        String humanPresentableName)
      Constructs a DataFlavor that represents as MimeType.

      The returned DataFlavor will have the following characteristics:

      If the mimeType is "application/x-java-serialized-object;
      class=<representation class>", the result is the same as calling new
      DataFlavor(Class:forName(<representation class>) as above.

      Otherwise:

      representationClass = InputStream
           mimeType = mimeType
       
      Parameters:
      mimeType - the string used to identify the MIME type for this flavor;
      if the the mimeType does not specify a "class=" parameter, or if the
      class is not successfully loaded, then an IllegalArgumentException is
      thrown
      humanPresentableName - the human-readable string used to identify this
      flavor; if this parameter is null then the value of the the MIME
      Content Type is used
      Throws:
      IllegalArgumentException - if mimeType is invalid or if the class is
      not successfully loaded
      =(2)==============================================================
      public DataFlavor(String mimeType,
                        String humanPresentableName,
                        ClassLoader classLoader)
                 throws ClassNotFoundException
      Constructs a DataFlavor that represents a MimeType.

      The returned DataFlavor will have the following characteristics:

      If the mimeType is "application/x-java-serialized-object;
      class=<representation class>", the result is the same as calling new
      DataFlavor(Class:forName(<representation class>) as above.

      Otherwise:

      representationClass = InputStream
           mimeType = mimeType
       
      Parameters:
      mimeType - the string used to identify the MIME type for this flavor
      humanPresentableName - the human-readible string used to identify this flavor
      classLoad - the class loader to use
      =(3)==============================================================
      public DataFlavor(String mimeType)
                 throws ClassNotFoundException
      Constructs a DataFlavor from a Mime Type string. The string can
      specify a "class=" parameter to create a DataFlavor with the desired
      representation class. If the string does not contain "class="
      parameter, java.io.InputStream is used as default.
      Parameters:
      mimeType - the string used to identify the MIME type for this flavor;
      if the class specified by "class=" parameter is not successfully
      loaded, then an ClassNotFoundException is thrown
      Throws:
      ClassNotFoundException - if the class is not loaded
      IllegalArgumentException - if mimeType is invalid
      ===============================================================
      In (1) and (3) javadoc says about ctor reaction on invalid 'mimeType'
      parameter. In (2) - does not.

      Simple test to demonstrate current behaviour:
      ------------------------------------------------------------
      import java.awt.datatransfer.*;

      public class Test2 {

        public static void main(String[] args) {
             
          String mimeType = "";
          String humanPresentableName = "MyType";

          DataFlavor df = null;
          try {
              df = new DataFlavor(mimeType);
          } catch (Exception e) {
              System.out.println(e);
          }

          try {
              df = new DataFlavor(mimeType, humanPresentableName);
          } catch (Exception e) {
              System.out.println(e);
          }

          try {
              df = new DataFlavor(mimeType,
                                  humanPresentableName,
                                  Test2.class.getClassLoader());
          } catch (Exception e) {
              System.out.println(e);
          }
        }
      }
      ------------------------------------------------------------
      Output:

      ] dsv@falcon ~/tmp
      ] java Test2
      java.lang.IllegalArgumentException: failed to parse:
      java.lang.IllegalArgumentException: failed to parse:
      java.lang.IllegalArgumentException: failed to parse:

      ] dsv@falcon ~/tmp
      ] java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b46)
      Java HotSpot(TM) Client VM (build 1.4beta-B45, mixed mode)
      ------------------------------------------------------------
      ======================================================================

            sharonz Sharon Zakhour (Inactive)
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: