jdk/test/java/rmi/invalidName/InvalidName.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 14778 5947768d173d
child 30820 0d4717a011d3
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 14778
diff changeset
     2
 * Copyright (c) 1998, 2012, 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
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4136563
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Naming.lookup fails to throw exception for invalid hostname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @bug 4208801
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @summary (1.x) java.rmi.Naming defaults to local hostname, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *          local IP address
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @author Laird Dornin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @library ../testlibrary
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    35
 * @build TestLibrary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @run main/othervm InvalidName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.rmi.registry.Registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.rmi.Naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class InvalidName {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        String testName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        // ensure that an exception is thrown for Naming URL with '#'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            System.err.println("\nRegression test for bugs " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                               "4136563 and 4208801\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            testName = new String("rmi://#/MyRMI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            Naming.lookup(testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            System.err.println("no exception thrown for URL: " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            throw new RuntimeException("test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            // should have received malformed URL exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            System.err.println("Correctly received instance of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                               "MalformedURLException:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            System.err.println(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            TestLibrary.bomb(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        // ensure a correct null pointer exception is thrown for null URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // ensure that a registry stub with a default hostname and one with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // the local host's ip address are .equals()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            String localAddress =  InetAddress.getLocalHost().getHostAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            Registry registry = (Registry) Naming.lookup("rmi:///");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (registry.toString().indexOf(localAddress) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                System.err.println("verified registry endpoint contains ipaddress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                TestLibrary.bomb("registry endpoint does not contain ipaddress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            TestLibrary.bomb(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        System.err.println("test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}