JDK-4402456 : URLDecoder.decode(String s, String enc) fails with certain input
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2001-01-06
  • Updated: 2001-01-08
  • Resolved: 2001-01-08
Related Reports
Duplicate :  
Relates :  
Description
URLDecoder.decode(String s, Stirng enc) is throwing java.nio.BufferOverflowException exception when it is called as follows
String encString = URLEncoder.encode("asdf @ $ adf", "UTF-16BE");
String decString= URLDecoder.decode(encString, "UTF-16BE");

This exception is coming with merlin build 46 on Solaris. 
Exception  :

java.nio.BufferOverflowException
        at java.nio.Buffer.nextPutIndex(Buffer.java:367)
        at java.nio.HeapCharBuffer.put(HeapCharBuffer.java:69)
        at java.nio.CharBuffer.put(CharBuffer.java:766)
        at java.nio.CharBuffer.put(CharBuffer.java:790)
        at java.nio.CharsetDecoder.decode(CharsetDecoder.java:292)
        at java.lang.StringCoding$CharsetSD.decode(StringCoding.java:159)
        at java.lang.StringCoding.decode(StringCoding.java:189)
        at java.lang.String.<init>(String.java:326)
        at java.net.URLDecoder.decode(URLDecoder.java:153)
        at EncodeDecode.performEncodeDecodeTests(EncodeDecode.java:104)
        at EncodeDecode.main(EncodeDecode.java:58)

How to reproduce this:

1. Take the attached EncodeDecode.java and EncodeDecode.data files.

2. Execute as :
  java EncodeDecode -f data/EncodeDecode.data -d

Other Information:

Particularly this exception is coming when input string to encoder is  one of these:
 "asdf $ $ asdf"
  "asdf @@ $$$ asdjflkad"


Comments
EVALUATION The exception is resolved by the fix to 4402326. The attached test program does show another problem whereby with UTF-16 some encoded strings are not decoded back to the original input. This problem is a peculiarity of UTF-16 (unlike UTF-16BE, and UTF16-LE) where encoded output is preceded by a two byte header (%FE%FF, or %FF%FE). The encoder outputs the header once, but the way the decoder is written it expects the header before every encoded byte. This issue will be resolved through another report. So, closing this a duplicate. michael.mcmahon@ireland 2001-01-08
08-01-2001