# HG changeset patch # User redestad # Date 1411137299 -7200 # Node ID 6b160d97c51dedb07a52e53982c28aee38ed14ef # Parent 2aa1709a8043fd81f554b25cf76ce13f96d59688 8055032: Improve numerical parsing in java.net and sun.net Reviewed-by: alanb diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/java/net/CookieManager.java --- a/jdk/src/java.base/share/classes/java/net/CookieManager.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/java/net/CookieManager.java Fri Sep 19 16:34:59 2014 +0200 @@ -368,7 +368,7 @@ int val = -1; while (i > 0) { try { - val = Integer.parseInt(lst.substring(0, i)); + val = Integer.parseInt(lst, 0, i, 10); if (val == port) { return true; } diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/java/net/URI.java --- a/jdk/src/java.base/share/classes/java/net/URI.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/java/net/URI.java Fri Sep 19 16:34:59 2014 +0200 @@ -3250,7 +3250,7 @@ if (q > p) { checkChars(p, q, L_DIGIT, H_DIGIT, "port number"); try { - port = Integer.parseInt(substring(p, q)); + port = Integer.parseInt(input, p, q, 10); } catch (NumberFormatException x) { fail("Malformed port number", p); } @@ -3271,7 +3271,7 @@ int p = start; int q = scan(p, n, L_DIGIT, H_DIGIT); if (q <= p) return q; - if (Integer.parseInt(substring(p, q)) > 255) return p; + if (Integer.parseInt(input, p, q, 10) > 255) return p; return q; } diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/java/net/URLDecoder.java --- a/jdk/src/java.base/share/classes/java/net/URLDecoder.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/java/net/URLDecoder.java Fri Sep 19 16:34:59 2014 +0200 @@ -171,7 +171,7 @@ while ( ((i+2) < numChars) && (c=='%')) { - int v = Integer.parseInt(s.substring(i+1,i+3),16); + int v = Integer.parseInt(s, i + 1, i + 3, 16); if (v < 0) throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value"); bytes[pos++] = (byte) v; diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/java/net/URLStreamHandler.java --- a/jdk/src/java.base/share/classes/java/net/URLStreamHandler.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/java/net/URLStreamHandler.java Fri Sep 19 16:34:59 2014 +0200 @@ -196,7 +196,8 @@ ++ind ; // port can be null according to RFC2396 if (nhost.length() > (ind + 1)) { - port = Integer.parseInt(nhost.substring(ind+1)); + port = Integer.parseInt(nhost, ind + 1, + nhost.length(), 10); } } else { throw new IllegalArgumentException( @@ -213,7 +214,8 @@ if (ind >= 0) { // port can be null according to RFC2396 if (host.length() > (ind + 1)) { - port = Integer.parseInt(host.substring(ind + 1)); + port = Integer.parseInt(host, ind + 1, + host.length(), 10); } host = host.substring(0, ind); } diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/sun/net/TransferProtocolClient.java --- a/jdk/src/java.base/share/classes/sun/net/TransferProtocolClient.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/sun/net/TransferProtocolClient.java Fri Sep 19 16:34:59 2014 +0200 @@ -80,7 +80,7 @@ code = -1; } else { try { - code = Integer.parseInt(response.substring(0, 3)); + code = Integer.parseInt(response, 0, 3, 10); } catch (NumberFormatException e) { code = -1; } catch (StringIndexOutOfBoundsException e) { diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java --- a/jdk/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java Fri Sep 19 16:34:59 2014 +0200 @@ -260,8 +260,8 @@ if (d != null && time != null) { int c = time.indexOf(':'); now.setTime(d); - now.set(Calendar.HOUR, Integer.parseInt(time.substring(0, c))); - now.set(Calendar.MINUTE, Integer.parseInt(time.substring(c + 1))); + now.set(Calendar.HOUR, Integer.parseInt(time, 0, c, 10)); + now.set(Calendar.MINUTE, Integer.parseInt(time, c + 1, time.length(), 10)); d = now.getTime(); } // see if it's a symbolic link, i.e. the name if followed @@ -437,7 +437,7 @@ code = -1; } else { try { - code = Integer.parseInt(response.substring(0, 3)); + code = Integer.parseInt(response, 0, 3, 10); } catch (NumberFormatException e) { code = -1; } catch (StringIndexOutOfBoundsException e) { diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/sun/net/www/ParseUtil.java --- a/jdk/src/java.base/share/classes/sun/net/www/ParseUtil.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/sun/net/www/ParseUtil.java Fri Sep 19 16:34:59 2014 +0200 @@ -161,7 +161,7 @@ * Un-escape and return the character at position i in string s. */ private static byte unescape(String s, int i) { - return (byte) Integer.parseInt(s.substring(i+1,i+3),16); + return (byte) Integer.parseInt(s, i + 1, i + 3, 16); } diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java --- a/jdk/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java Fri Sep 19 16:34:59 2014 +0200 @@ -313,7 +313,7 @@ break; } try { - chunkSize = Integer.parseInt(header.substring(0, i), 16); + chunkSize = Integer.parseInt(header, 0, i, 16); } catch (NumberFormatException e) { error = true; throw new IOException("Bogus chunk size"); diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/share/classes/sun/net/www/http/HttpClient.java --- a/jdk/src/java.base/share/classes/sun/net/www/http/HttpClient.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/share/classes/sun/net/www/http/HttpClient.java Fri Sep 19 16:34:59 2014 +0200 @@ -808,7 +808,7 @@ ind = resp.indexOf(' '); while(resp.charAt(ind) == ' ') ind++; - code = Integer.parseInt(resp.substring(ind, ind + 3)); + code = Integer.parseInt(resp, ind, ind + 3, 10); } catch (Exception e) {} if (code == HTTP_CONTINUE && ignoreContinue) { diff -r 2aa1709a8043 -r 6b160d97c51d jdk/src/java.base/unix/classes/sun/net/sdp/SdpProvider.java --- a/jdk/src/java.base/unix/classes/sun/net/sdp/SdpProvider.java Fri Sep 19 16:49:08 2014 +0400 +++ b/jdk/src/java.base/unix/classes/sun/net/sdp/SdpProvider.java Fri Sep 19 16:34:59 2014 +0200 @@ -257,7 +257,8 @@ .getByName(s[1].substring(0, pos)); int prefix = -1; try { - prefix = Integer.parseInt(s[1].substring(pos+1)); + prefix = Integer.parseInt(s[1], pos + 1, + s[1].length(), 10); if (address instanceof Inet4Address) { // must be 1-31 if (prefix < 0 || prefix > 32) prefix = -1;