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

TextFlavor.getXXXforXXXEncodingForCharset works wrong

XMLWordPrintable

    • sparc
    • solaris_2.5.1



      Name: sdC67446 Date: 06/18/99


      The methods
          public String getByteToCharEncodingForCharset(String charset)
          public String getCharToByteEncodingForCharset(String charset)
      of class java.awt.datatransfer.TextFlavor
      dont return getDefaultCharset() for null input parameter as doc says.

      The JDK javadoc comment says:
      --------------------------------------------------
          /**
           * Gets the encoding that can be used to interpret this
           * charset. For instance, <code>ISO8859_1</code> decoding
           * <i>may</i> be used to interpret an <code>ascii</code>
           * charset stream. The value returned can be passed in
           * as a character encoding to other JDK classes, such as
           * <code>java.io.InputStreamReader</code>.
           * <p>
           * The MIME specification requires that all MIME values
           * be lower case. MIME types with upper-case values are
           * in error and may yield unpredictable results.
           * </p>
           *
           * @param charset The charset to be decoded. If charset is
           * <code>null</code>, the value returned by
           * <code>getDefaultCharset()</code> is used.
                          ^^^^^^^^^^^^^^^^^^^
           *
           * @return the appropriate character encoding, or <code>null</code>
           * if no decoder is available.
           */

          public String getByteToCharEncodingForCharset(String charset)
          
          public String getCharToByteEncodingForCharset(String charset)

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

      public class Test {

          public static void main(String[] args) {
              try {
                  TextFlavor tf = new TextFlavor("text/plain");
                  System.out.println("getDefaultCharset(): "+tf.getDefaultCharset());

                  System.out.println("getByteToCharEncodingForCharset(null): "+
                                     tf.getByteToCharEncodingForCharset(null));
                  System.out.println("getCharToByteEncodingForCharset(null): "+
                                     tf.getCharToByteEncodingForCharset(null));

                  System.out.println(tf.getCharToByteEncodingForCharset(null).equals(tf.getDefaultCharset()));
                  
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              }
          }
      }
      ---------Output-----------------------------------
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      Font specified in font.properties not found [-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
      getDefaultCharset(): iso8859-1
      getByteToCharEncodingForCharset(null): ISO8859_1
      getCharToByteEncodingForCharset(null): ISO8859_1
      false
      ^C
      --------------------------------------------------
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: