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

classes in networking use String.getBytes - native encoding incorrectly assumed

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 1.4.2
    • core-libs
    • None
    • b28
    • generic
    • generic

      This is the net related part of bug 4927428 which reports the following
      general problem in the jdk.


      We are currently into porting J2SE V1.4.2 to our mainframe platform,
      where the native encoding is EBCDIC. Several tests in JCK failed because
      of the careless use of java.lang.String.getBytes() in other java classes;
      use of native encoding is essentially wrongfully hardcoded into these
      classes.

      We compiled the following list of modifications that were necessary to
      pass the JCK tests. There are a lot more suspicious uses of getBytes(),
      where we were not able to decide whether their usage is right or wrong.

      ACTION ITEM:
      Please initiate some kind of overall review of the encoding issue,
      and fix all java classes where the problem occurs.

      === Start of list ===

      The method getBytes() in java.lang.String converts implictly with native
      encoding. The usage of this method on machines where native encoding is
      not ISO-8859-1 or some compatible ASCII encoding is wrong in J2SE SDK
      1.4.2 in the following cases.

      java/net/SocksSocketImpl.java
      // all occurrences of getBytes() have to be changed to
      // getBytes("ISO-8859-1")


      sun/net/www/protocol/http/BasicAuthentication.java
      // wrong lines 42 and 76
      byte[] nameBytes = plain.getBytes();
      // correction:
      byte[] nameBytes = null;
      try {
      nameBytes = plain.getBytes("ISO-8859-1");
      } catch (java.io.UnsupportedEncodingException dummyexc) {
      // cannot happen
      }

                    
      sun/net/www/protocol/http/DigestAuthentication.java
      // wrong line 488
      md.update(src.getBytes());
      // correction:
      try {
      md.update(src.getBytes("ISO-8859-1"));
      } catch (java.io.UnsupportedEncodingException dummyexc) {
      // cannot happen
      }

      === end of list ===

            jccollet Jean-Christophe Collet (Inactive)
            iris Iris Clark
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: