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

Behavior of SystemFlavorMap encoding methods is inconsistent

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.6



      Name: sdC67446 Date: 12/08/99


      1) Two similar methods has different behaviors if input param == null:
            public static String encodeJavaMIMEType(String mimeType)
            public static String encodeDataFlavor(DataFlavor df)

          The first one returns empty encoded string,
          the second one - throws NPE.

      2) Also the problem with the pair of methods:

            public static String encodeJavaMIMEType(String mimeType)
            public static String decodeJavaMIMEType(String atom)

           decodeJavaMIMEType(encodeJavaMIMEType(null)) != null
              
      3) The doc should clarify what the "encoded" mimetype string looks
         like.

      The javadoc says:
      --------------------------------------------------
      public static String encodeJavaMIMEType(String mimeType)

            Returns:
                  encode a Java MIMEType for use as a native type name


      public static String encodeDataFlavor(DataFlavor df)

            Returns:
                  encode a Java MIMEType for use as a native type name


      public static boolean isJavaMIMEType(String atom)

            Returns:
                  if the native type string is an encoded Java MIMEType


      the test demonstraiting the 1st point:
      --------------------------------------------------
      import java.awt.datatransfer.*;

      public class Test {
          public static void main(String[] args) {
              System.out.println(" --- 1 --- ");
              System.out.println(SystemFlavorMap.encodeJavaMIMEType(null));
              System.out.println(" --- 2 --- ");
              try {
                  System.out.println(SystemFlavorMap.encodeDataFlavor(null));
              } catch (NullPointerException e) {
                  System.out.println("Unexpected: "+e);
              }
              System.out.println(" --- 3 --- ");
              if (
                  SystemFlavorMap.decodeJavaMIMEType(SystemFlavorMap.encodeJavaMIMEType(null)) != null ) {
                  System.out.println("decodeJavaMIMEType(encodeDataFlavor(null)) != null");
              }
          }
      }

      output:
      --------------------------------------------------
       --- 1 ---
      JAVA_DATAFLAVOR:null
       --- 2 ---
      Unexpected: java.lang.NullPointerException
       --- 3 ---
      decodeJavaMIMEType(encodeDataFlavor(null)) != null
      --------------------------------------------------
      ======================================================================

            dmendenhsunw David Mendenhall (Inactive)
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: