0N/A/*
2362N/A * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4749938
0N/A * @summary Bug in the parsing IPv4 literal addresses
0N/A*/
0N/A
0N/Aimport java.net.InetAddress;
0N/Aimport java.net.UnknownHostException;
0N/Aimport java.util.*;
0N/A
0N/Apublic class textToNumericFormat {
0N/A
0N/A public static void main(String[] args) throws UnknownHostException {
0N/A List goodList = new ArrayList();
0N/A List badList = new ArrayList();
0N/A String goodAddrs[] = {
0N/A "224.0.1.0",
0N/A "238.255.255.255",
0N/A "239.255.255.255" };
0N/A
0N/A String badAddrs[] = {
0N/A "238.255.255.2550",
0N/A "256.255.255.255",
0N/A "238.255.2550.255",
0N/A "238.2550.255.255",
0N/A "2380.255.255.255"};
0N/A
0N/A for (int i=0; i<goodAddrs.length; i++) {
0N/A try {
0N/A InetAddress ia = InetAddress.getByName(goodAddrs[i]);
0N/A } catch (UnknownHostException e) {
0N/A // shouldn't have come here
0N/A goodList.add(goodAddrs[i]);
0N/A }
0N/A
0N/A }
0N/A
0N/A for (int i=0; i<badAddrs.length; i++) {
0N/A try {
0N/A InetAddress ia = InetAddress.getByName(badAddrs[i]);
0N/A // shouldn't have come here
0N/A badList.add(badAddrs[i]);
0N/A } catch (UnknownHostException e) {
0N/A // ignore
0N/A }
0N/A
0N/A }
0N/A
0N/A // if either goodList or badList is not empty, throw exception
0N/A if (goodList.size() > 0 || badList.size() > 0) {
0N/A throw new RuntimeException((goodList.size() > 0?
0N/A ("Good address not parsed: "+ goodList)
0N/A : "") +
0N/A (badList.size() > 0 ?
0N/A ("Bad Address parsed: "+ badList)
0N/A : ""));
0N/A }
0N/A
0N/A }
0N/A
0N/A}