jdk/test/java/rmi/invalidName/InvalidName.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 23010 6dadb192ad81
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
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
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23010
diff changeset
    35
 * @modules java.rmi/sun.rmi.registry
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23010
diff changeset
    36
 *          java.rmi/sun.rmi.server
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23010
diff changeset
    37
 *          java.rmi/sun.rmi.transport
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23010
diff changeset
    38
 *          java.rmi/sun.rmi.transport.tcp
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    39
 * @build TestLibrary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @run main/othervm InvalidName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.registry.Registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.rmi.Naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class InvalidName {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        String testName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // ensure that an exception is thrown for Naming URL with '#'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            System.err.println("\nRegression test for bugs " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                               "4136563 and 4208801\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            testName = new String("rmi://#/MyRMI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            Naming.lookup(testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            System.err.println("no exception thrown for URL: " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            throw new RuntimeException("test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            // should have received malformed URL exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            System.err.println("Correctly received instance of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                               "MalformedURLException:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            System.err.println(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            TestLibrary.bomb(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // ensure a correct null pointer exception is thrown for null URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        // ensure that a registry stub with a default hostname and one with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // the local host's ip address are .equals()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            String localAddress =  InetAddress.getLocalHost().getHostAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            Registry registry = (Registry) Naming.lookup("rmi:///");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            if (registry.toString().indexOf(localAddress) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                System.err.println("verified registry endpoint contains ipaddress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                TestLibrary.bomb("registry endpoint does not contain ipaddress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            TestLibrary.bomb(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        System.err.println("test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}