JDK-4354951 : URLEncoder.encode returns incorrect value when input is >= 128.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2000-07-20
  • Updated: 2000-07-25
  • Resolved: 2000-07-25
Related Reports
Duplicate :  
Description
Hostname: jtgbp62e
Hostid: 2be09290
Release: 5.8
Kernel architecture: i86pc
Application architecture: i386
Hardware provider: 
Domain: sunsoft.eng.sun.com
Kernel version: SunOS 5.8 Generic February 2000

jtgbp62e>psrinfo -v
Status of processor 0 as of: 07/20/00 11:13:18
  Processor has been on-line since 07/06/00 15:39:45.
  The i386 processor operates at 600 MHz,
        and has an i387 compatible floating point processor.
Status of processor 1 as of: 07/20/00 11:13:18
  Processor has been on-line since 07/06/00 15:39:49.
  The i386 processor operates at 600 MHz,
        and has an i387 compatible floating point processor.

jtgbp62e>cat /etc/release
                           Solaris 8 s28_38shwp2 INTEL
           Copyright 2000 Sun Microsystems, Inc.  All Rights Reserved.
                            Assembled 21 January 2000


To reproduce, run the attached script "index_Encode.ksh".

Runtime ouptut:
===============
jtgbp62e>./index_Encode.ksh
Compiling ... 

Note: EncodeTests.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

Running ... 

URLEncoder0003: Failed. Encoding failed : 128 %EF%BF%BD %3F
STATUS:Failed. tests: 1; failed: 1; first test case failure: URLEncoder0003
97


takwing.cheung@Eng 2000-07-20

Comments
EVALUATION mayank.upadhyay@eng 2000-07-25 I don't agree that this is a duplicate of 4316925. That was a different problem. However, this report is still not a bug because the test program is expecting incorrect results. Prior to Merlin build 12 the URLEncoder/Decoder classes were broken with respect to characters beyond the US-ASCII range (0-127). This test depends on that behaviour. As per that behaviour, any byte whose value is above 127 is converted to the character '?' which is encoded as %3F. Therefore, all characters in the test that range from 128 to 255 were encoded as %3F. The following bugs were fixed in Melrin build 12: 4257115: java.net.URLEncoder class and java.net.URLDecoder class can't encode and decode 4206144: Request more precise specification of java.net.URLEncoder.encode 4316925: URLEncoder.encode(String) works wrong when external encoding is set As a result the URLEncoder now returns the correct UTF-8 based encoding of charcters. For US-ASCII characters the UTF-8 encoding is the same as the US-ASCII encoding. But for characters starting at 128 the encoding is different. The test should be modified to expect the UTF-8 based encoding. The new javadocs for this class explain how this works. Also, if the test wishes to encode as per the old behaviour for characters >= 128, then it must invoke the URLEncoder.encode(String str, String enc) method with enc="ascii".
11-06-2004

PUBLIC COMMENTS See Bug ID 4316925 or 4257115
10-06-2004