J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
Lana Steuck | 657b9db | 2013-12-26 12:04:16 -0800 | [diff] [blame] | 2 | * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
Kelly O'Hair | fe008ae | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 4136563 |
| 26 | * @summary Naming.lookup fails to throw exception for invalid hostname |
| 27 | * |
| 28 | * @bug 4208801 |
| 29 | * @summary (1.x) java.rmi.Naming defaults to local hostname, not |
| 30 | * local IP address |
| 31 | * |
| 32 | * @author Laird Dornin |
| 33 | * |
| 34 | * @library ../testlibrary |
Mandy Chung | 53a97cb | 2015-05-28 10:54:48 -0700 | [diff] [blame] | 35 | * @modules java.rmi/sun.rmi.registry |
| 36 | * java.rmi/sun.rmi.server |
| 37 | * java.rmi/sun.rmi.transport |
| 38 | * java.rmi/sun.rmi.transport.tcp |
Stuart Marks | 38887c7 | 2012-12-12 09:53:01 -0800 | [diff] [blame] | 39 | * @build TestLibrary |
J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 40 | * @run main/othervm InvalidName |
| 41 | */ |
| 42 | |
| 43 | import java.net.URL; |
| 44 | import java.net.InetAddress; |
| 45 | import java.net.MalformedURLException; |
| 46 | import java.rmi.registry.Registry; |
| 47 | import java.rmi.Naming; |
| 48 | import java.rmi.Remote; |
| 49 | import java.rmi.server.RemoteObject; |
| 50 | import java.rmi.server.UnicastRemoteObject; |
| 51 | |
| 52 | public class InvalidName { |
| 53 | public static void main(String[] args) { |
| 54 | |
| 55 | String testName; |
| 56 | |
| 57 | // ensure that an exception is thrown for Naming URL with '#' |
| 58 | try { |
| 59 | |
| 60 | System.err.println("\nRegression test for bugs " + |
| 61 | "4136563 and 4208801\n"); |
| 62 | |
| 63 | testName = new String("rmi://#/MyRMI"); |
| 64 | |
| 65 | Naming.lookup(testName); |
| 66 | System.err.println("no exception thrown for URL: " + testName); |
| 67 | throw new RuntimeException("test failed"); |
| 68 | |
| 69 | } catch (MalformedURLException e) { |
| 70 | // should have received malformed URL exception |
| 71 | System.err.println("Correctly received instance of " + |
| 72 | "MalformedURLException:"); |
| 73 | System.err.println(e.getMessage()); |
| 74 | e.printStackTrace(); |
| 75 | |
| 76 | } catch (Exception e) { |
| 77 | TestLibrary.bomb(e); |
| 78 | } |
| 79 | |
| 80 | // ensure a correct null pointer exception is thrown for null URL |
| 81 | // ensure that a registry stub with a default hostname and one with a |
| 82 | // the local host's ip address are .equals() |
| 83 | try { |
| 84 | String localAddress = InetAddress.getLocalHost().getHostAddress(); |
| 85 | |
| 86 | Registry registry = (Registry) Naming.lookup("rmi:///"); |
| 87 | |
| 88 | if (registry.toString().indexOf(localAddress) >= 0) { |
| 89 | System.err.println("verified registry endpoint contains ipaddress"); |
| 90 | } else { |
| 91 | TestLibrary.bomb("registry endpoint does not contain ipaddress"); |
| 92 | } |
| 93 | } catch (Exception e) { |
| 94 | TestLibrary.bomb(e); |
| 95 | } |
| 96 | |
| 97 | System.err.println("test passed"); |
| 98 | } |
| 99 | } |