src/java.base/share/classes/java/net/HostPortrange.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 52700 b206bdfb9fe2
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     1
/*
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     4
 *
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    10
 *
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    15
 * accompanied this code).
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    16
 *
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    20
 *
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    23
 * questions.
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    24
 */
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    25
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    26
package java.net;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    27
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    28
import java.net.*;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    29
import java.util.Formatter;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    30
import java.util.Locale;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    31
import sun.net.util.IPAddressUtil;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    32
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    33
/**
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    34
 * Parses a string containing a host/domain name and port range
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    35
 */
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    36
class HostPortrange {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    37
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    38
    String hostname;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    39
    String scheme;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    40
    int[] portrange;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    41
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    42
    boolean wildcard;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    43
    boolean literal;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    44
    boolean ipv6, ipv4;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    45
    static final int PORT_MIN = 0;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    46
    static final int PORT_MAX = (1 << 16) -1;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    47
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    48
    boolean equals(HostPortrange that) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    49
        return this.hostname.equals(that.hostname)
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    50
            && this.portrange[0] == that.portrange[0]
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    51
            && this.portrange[1] == that.portrange[1]
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    52
            && this.wildcard == that.wildcard
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    53
            && this.literal == that.literal;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    54
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    55
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    56
    public int hashCode() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    57
        return hostname.hashCode() + portrange[0] + portrange[1];
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    58
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    59
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    60
    HostPortrange(String scheme, String str) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    61
        // Parse the host name.  A name has up to three components, the
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    62
        // hostname, a port number, or two numbers representing a port
52700
b206bdfb9fe2 8213911: Use example.com in java.net and other examples
darcy
parents: 47216
diff changeset
    63
        // range.   "www.example.com:8080-9090" is a valid host name.
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    64
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    65
        // With IPv6 an address can be 2010:836B:4179::836B:4179
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    66
        // An IPv6 address needs to be enclose in []
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    67
        // For ex: [2010:836B:4179::836B:4179]:8080-9090
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    68
        // Refer to RFC 2732 for more information.
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    69
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    70
        // first separate string into two fields: hoststr, portstr
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    71
        String hoststr, portstr = null;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    72
        this.scheme = scheme;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    73
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    74
        // check for IPv6 address
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    75
        if (str.charAt(0) == '[') {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    76
            ipv6 = literal = true;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    77
            int rb = str.indexOf(']');
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    78
            if (rb != -1) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    79
                hoststr = str.substring(1, rb);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    80
            } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    81
                throw new IllegalArgumentException("invalid IPv6 address: " + str);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    82
            }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    83
            int sep = str.indexOf(':', rb + 1);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    84
            if (sep != -1 && str.length() > sep) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    85
                portstr = str.substring(sep + 1);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    86
            }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    87
            // need to normalize hoststr now
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    88
            byte[] ip = IPAddressUtil.textToNumericFormatV6(hoststr);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    89
            if (ip == null) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    90
                throw new IllegalArgumentException("illegal IPv6 address");
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    91
            }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    92
            StringBuilder sb = new StringBuilder();
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    93
            Formatter formatter = new Formatter(sb, Locale.US);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    94
            formatter.format("%02x%02x:%02x%02x:%02x%02x:%02x"
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    95
                    + "%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    96
                    ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8],
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    97
                    ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    98
            hostname = sb.toString();
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
    99
        } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   100
            // not IPv6 therefore ':' is the port separator
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   101
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   102
            int sep = str.indexOf(':');
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   103
            if (sep != -1 && str.length() > sep) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   104
                hoststr = str.substring(0, sep);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   105
                portstr = str.substring(sep + 1);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   106
            } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   107
                hoststr = sep == -1 ? str : str.substring(0, sep);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   108
            }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   109
            // is this a domain wildcard specification?
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   110
            if (hoststr.lastIndexOf('*') > 0) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   111
                throw new IllegalArgumentException("invalid host wildcard specification");
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   112
            } else if (hoststr.startsWith("*")) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   113
                wildcard = true;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   114
                if (hoststr.equals("*")) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   115
                    hoststr = "";
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   116
                } else if (hoststr.startsWith("*.")) {
21608
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   117
                    hoststr = toLowerCase(hoststr.substring(1));
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   118
                } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   119
                    throw new IllegalArgumentException("invalid host wildcard specification");
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   120
                }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   121
            } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   122
                // check if ipv4 (if rightmost label a number)
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   123
                // The normal way to specify ipv4 is 4 decimal labels
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   124
                // but actually three, two or single label formats valid also
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   125
                // So, we recognise ipv4 by just testing the rightmost label
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   126
                // being a number.
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   127
                int lastdot = hoststr.lastIndexOf('.');
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   128
                if (lastdot != -1 && (hoststr.length() > 1)) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   129
                    boolean ipv4 = true;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   130
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   131
                    for (int i = lastdot + 1, len = hoststr.length(); i < len; i++) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   132
                        char c = hoststr.charAt(i);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   133
                        if (c < '0' || c > '9') {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   134
                            ipv4 = false;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   135
                            break;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   136
                        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   137
                    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   138
                    this.ipv4 = this.literal = ipv4;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   139
                    if (ipv4) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   140
                        byte[] ip = IPAddressUtil.textToNumericFormatV4(hoststr);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   141
                        if (ip == null) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   142
                            throw new IllegalArgumentException("illegal IPv4 address");
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   143
                        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   144
                        StringBuilder sb = new StringBuilder();
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   145
                        Formatter formatter = new Formatter(sb, Locale.US);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   146
                        formatter.format("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   147
                        hoststr = sb.toString();
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   148
                    } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   149
                        // regular domain name
21608
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   150
                        hoststr = toLowerCase(hoststr);
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   151
                    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   152
                }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   153
            }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   154
            hostname = hoststr;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   155
        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   156
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   157
        try {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   158
            portrange = parsePort(portstr);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   159
        } catch (Exception e) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   160
            throw new IllegalArgumentException("invalid port range: " + portstr);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   161
        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   162
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   163
21608
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   164
    static final int CASE_DIFF = 'A' - 'a';
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   165
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   166
    /**
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   167
     * Convert to lower case, and check that all chars are ascii
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   168
     * alphanumeric, '-' or '.' only.
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   169
     */
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   170
    static String toLowerCase(String s) {
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   171
        int len = s.length();
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   172
        StringBuilder sb = null;
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   173
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   174
        for (int i=0; i<len; i++) {
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   175
            char c = s.charAt(i);
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   176
            if ((c >= 'a' && c <= 'z') || (c == '.')) {
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   177
                if (sb != null)
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   178
                    sb.append(c);
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   179
            } else if ((c >= '0' && c <= '9') || (c == '-')) {
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   180
                if (sb != null)
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   181
                    sb.append(c);
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   182
            } else if (c >= 'A' && c <= 'Z') {
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   183
                if (sb == null) {
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   184
                    sb = new StringBuilder(len);
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   185
                    sb.append(s, 0, i);
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   186
                }
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   187
                sb.append((char)(c - CASE_DIFF));
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   188
            } else {
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   189
                throw new IllegalArgumentException("Invalid characters in hostname");
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   190
            }
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   191
        }
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   192
        return sb == null ? s : sb.toString();
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   193
    }
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   194
73c4bf75786c 8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents: 20787
diff changeset
   195
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   196
    public boolean literal() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   197
        return literal;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   198
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   199
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   200
    public boolean ipv4Literal() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   201
        return ipv4;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   202
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   203
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   204
    public boolean ipv6Literal() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   205
        return ipv6;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   206
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   207
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   208
    public String hostname() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   209
        return hostname;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   210
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   211
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   212
    public int[] portrange() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   213
        return portrange;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   214
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   215
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   216
    /**
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   217
     * returns true if the hostname part started with *
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   218
     * hostname returns the remaining part of the host component
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   219
     * eg "*.foo.com" -> ".foo.com" or "*" -> ""
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   220
     *
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   221
     * @return
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   222
     */
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   223
    public boolean wildcard() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   224
        return wildcard;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   225
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   226
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   227
    // these shouldn't leak outside the implementation
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   228
    static final int[] HTTP_PORT = {80, 80};
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   229
    static final int[] HTTPS_PORT = {443, 443};
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   230
    static final int[] NO_PORT = {-1, -1};
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   231
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   232
    int[] defaultPort() {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   233
        if (scheme.equals("http")) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   234
            return HTTP_PORT;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   235
        } else if (scheme.equals("https")) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   236
            return HTTPS_PORT;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   237
        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   238
        return NO_PORT;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   239
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   240
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   241
    int[] parsePort(String port)
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   242
    {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   243
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 52700
diff changeset
   244
        if (port == null || port.isEmpty()) {
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   245
            return defaultPort();
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   246
        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   247
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   248
        if (port.equals("*")) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   249
            return new int[] {PORT_MIN, PORT_MAX};
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   250
        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   251
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   252
        try {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   253
            int dash = port.indexOf('-');
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   254
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   255
            if (dash == -1) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   256
                int p = Integer.parseInt(port);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   257
                return new int[] {p, p};
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   258
            } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   259
                String low = port.substring(0, dash);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   260
                String high = port.substring(dash+1);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   261
                int l,h;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   262
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 52700
diff changeset
   263
                if (low.isEmpty()) {
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   264
                    l = PORT_MIN;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   265
                } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   266
                    l = Integer.parseInt(low);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   267
                }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   268
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 52700
diff changeset
   269
                if (high.isEmpty()) {
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   270
                    h = PORT_MAX;
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   271
                } else {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   272
                    h = Integer.parseInt(high);
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   273
                }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   274
                if (l < 0 || h < 0 || h<l) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   275
                    return defaultPort();
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   276
                }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   277
                return new int[] {l, h};
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   278
             }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   279
        } catch (IllegalArgumentException e) {
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   280
            return defaultPort();
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   281
        }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   282
    }
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
diff changeset
   283
}