--- old/src/share/classes/com/sun/jndi/toolkit/url/UrlUtil.java 2012-03-06 16:19:04.615035035 +0800 +++ new/src/share/classes/com/sun/jndi/toolkit/url/UrlUtil.java 2012-03-06 16:19:04.195035035 +0800 @@ -27,6 +27,7 @@ import java.net.MalformedURLException; import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; /** * Utilities for dealing with URLs. @@ -61,29 +62,14 @@ * The string is subsequently converted using the specified encoding */ public static final String decode(String s, String enc) - throws MalformedURLException, UnsupportedEncodingException { - - int length = s.length(); - byte[] bytes = new byte[length]; - int j = 0; - - for (int i = 0; i < length; i++) { - if (s.charAt(i) == '%') { - i++; // skip % - try { - bytes[j++] = (byte) - Integer.parseInt(s.substring(i, i + 2), 16); - - } catch (Exception e) { - throw new MalformedURLException("Invalid URI encoding: " + s); - } - i++; // skip first hex char; for loop will skip second one - } else { - bytes[j++] = (byte) s.charAt(i); - } + throws MalformedURLException, UnsupportedEncodingException { + try { + return URLDecoder.decode(s, enc); + } catch (IllegalArgumentException iae) { + MalformedURLException mue = new MalformedURLException("Invalid URI encoding: " + s); + mue.initCause(iae); + throw mue; } - - return new String(bytes, 0, j, enc); } /**