jdk/test/java/net/Inet4Address/textToNumericFormat.java
author robm
Tue, 25 Aug 2015 14:07:08 +0100
changeset 32271 d6cb1602f271
parent 30820 0d4717a011d3
child 36967 d041d2e80712
permissions -rw-r--r--
8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String) Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
32271
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 30820
diff changeset
    26
 * @bug 4749938 8087190
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Bug in the parsing IPv4 literal addresses
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 24124
diff changeset
    28
 * @modules java.base/sun.net.spi.nameservice
24124
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    29
 * @compile -XDignore.symbol.file=true DummyNameService.java DummyNameServiceDescriptor.java
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    30
 * @run main/othervm -Dsun.net.spi.nameservice.provider.1=dummy,oracle textToNumericFormat
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
24124
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    33
/**
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    34
 * We use a dummy name service which throws UHE any time it is called.
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    35
 * We do this because the "good" tests here should parse correctly
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    36
 * without needing to call the name service, and the bad tests will
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    37
 * not parse and then invoke the name service, where we expect
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    38
 * the exception.
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    39
 */
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class textToNumericFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args) throws UnknownHostException {
24042
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    48
        List<String> goodList = new ArrayList<>();
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    49
        List<String> badList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        String goodAddrs[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                           "224.0.1.0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                           "238.255.255.255",
24042
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    53
                           "239.255.255.255",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    54
                           "239.255.65535",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    55
                           "239.16777215",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    56
                           "4294967295" };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        String badAddrs[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                           "238.255.255.2550",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                           "256.255.255.255",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                           "238.255.2550.255",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                           "238.2550.255.255",
24042
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    63
                           "2380.255.255.255",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    64
                           "239.255.65536",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    65
                           "239.16777216",
32271
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 30820
diff changeset
    66
                           "4294967296",
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 30820
diff changeset
    67
                           ".1.1.1",
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 30820
diff changeset
    68
                           "1..1.1",
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 30820
diff changeset
    69
                           "1.1.1.",
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 30820
diff changeset
    70
                           "..." };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        for (int i=0; i<goodAddrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                InetAddress ia = InetAddress.getByName(goodAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                // shouldn't have come here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                goodList.add(goodAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        for (int i=0; i<badAddrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                InetAddress ia = InetAddress.getByName(badAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                // shouldn't have come here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                badList.add(badAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // if either goodList or badList is not empty, throw exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (goodList.size() > 0 || badList.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new RuntimeException((goodList.size() > 0?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                        ("Good address not parsed: "+ goodList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                        : "") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                       (badList.size() > 0 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                        ("Bad Address parsed: "+ badList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                        : ""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}