JDK-4937514 : classes in networking use String.getBytes - native encoding incorrectly assumed
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2003-10-14
  • Updated: 2003-11-03
  • Resolved: 2003-11-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b28Fixed
Related Reports
Relates :  
Description
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 ===


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b28 tiger-beta
14-06-2004

EVALUATION Yes, we should fix this. Will do as suggested for Tiger. ###@###.### 2003-10-17
17-10-2003