jdk/test/java/net/Inet4Address/textToNumericFormat.java
author michaelm
Mon, 28 Apr 2014 13:49:49 +0100
changeset 24124 5f5f7f7a4328
parent 24042 82290278c4af
child 30820 0d4717a011d3
permissions -rw-r--r--
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4749938
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Bug in the parsing IPv4 literal addresses
24124
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    28
 * @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
    29
 * @run main/othervm -Dsun.net.spi.nameservice.provider.1=dummy,oracle textToNumericFormat
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
24124
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    32
/**
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    33
 * 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
    34
 * 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
    35
 * 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
    36
 * 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
    37
 * the exception.
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    38
 */
5f5f7f7a4328 8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents: 24042
diff changeset
    39
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class textToNumericFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static void main(String[] args) throws UnknownHostException {
24042
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    47
        List<String> goodList = new ArrayList<>();
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    48
        List<String> badList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        String goodAddrs[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                           "224.0.1.0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                           "238.255.255.255",
24042
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    52
                           "239.255.255.255",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    53
                           "239.255.65535",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    54
                           "239.16777215",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    55
                           "4294967295" };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        String badAddrs[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                           "238.255.255.2550",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                           "256.255.255.255",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                           "238.255.2550.255",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                           "238.2550.255.255",
24042
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    62
                           "2380.255.255.255",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    63
                           "239.255.65536",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    64
                           "239.16777216",
82290278c4af 8040747: Improve performance of IP address parsing
mduigou
parents: 5506
diff changeset
    65
                           "4294967296" };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        for (int i=0; i<goodAddrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                InetAddress ia = InetAddress.getByName(goodAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                // shouldn't have come here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                goodList.add(goodAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        for (int i=0; i<badAddrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                InetAddress ia = InetAddress.getByName(badAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                // shouldn't have come here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                badList.add(badAddrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // if either goodList or badList is not empty, throw exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (goodList.size() > 0 || badList.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new RuntimeException((goodList.size() > 0?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                        ("Good address not parsed: "+ goodList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                        : "") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                       (badList.size() > 0 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                        ("Bad Address parsed: "+ badList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                        : ""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
}