Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/invalidName/InvalidName.java
38813 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 413656325* @summary Naming.lookup fails to throw exception for invalid hostname26*27* @bug 420880128* @summary (1.x) java.rmi.Naming defaults to local hostname, not29* local IP address30*31* @author Laird Dornin32*33* @library ../testlibrary34* @build TestLibrary35* @run main/othervm InvalidName36*/3738import java.net.URL;39import java.net.InetAddress;40import java.net.MalformedURLException;41import java.rmi.registry.Registry;42import java.rmi.Naming;43import java.rmi.Remote;44import java.rmi.server.RemoteObject;45import java.rmi.server.UnicastRemoteObject;4647public class InvalidName {48public static void main(String[] args) {4950String testName;5152// ensure that an exception is thrown for Naming URL with '#'53try {5455System.err.println("\nRegression test for bugs " +56"4136563 and 4208801\n");5758testName = new String("rmi://#/MyRMI");5960Naming.lookup(testName);61System.err.println("no exception thrown for URL: " + testName);62throw new RuntimeException("test failed");6364} catch (MalformedURLException e) {65// should have received malformed URL exception66System.err.println("Correctly received instance of " +67"MalformedURLException:");68System.err.println(e.getMessage());69e.printStackTrace();7071} catch (Exception e) {72TestLibrary.bomb(e);73}7475// ensure a correct null pointer exception is thrown for null URL76// ensure that a registry stub with a default hostname and one with a77// the local host's ip address are .equals()78try {79String localAddress = InetAddress.getLocalHost().getHostAddress();8081Registry registry = (Registry) Naming.lookup("rmi:///");8283if (registry.toString().indexOf(localAddress) >= 0) {84System.err.println("verified registry endpoint contains ipaddress");85} else {86TestLibrary.bomb("registry endpoint does not contain ipaddress");87}88} catch (Exception e) {89TestLibrary.bomb(e);90}9192System.err.println("test passed");93}94}959697