author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
16872 | 1 |
/* |
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
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 |
* |
|
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. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8001040 |
|
27 |
* @summary Tests proper parsing and defaulting of the |
|
28 |
* "java.rmi.server.useCodebaseOnly" property. |
|
29 |
* |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
30820
diff
changeset
|
30 |
* @modules java.rmi/sun.rmi.server:+open |
16872 | 31 |
* @run main/othervm UseCodebaseOnlyDefault true |
32 |
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=xyzzy UseCodebaseOnlyDefault true |
|
33 |
* @run main/othervm -Djava.rmi.server.useCodebaseOnly UseCodebaseOnlyDefault true |
|
34 |
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=true UseCodebaseOnlyDefault true |
|
35 |
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=false UseCodebaseOnlyDefault false |
|
36 |
*/ |
|
37 |
||
38 |
import java.io.ByteArrayInputStream; |
|
39 |
import java.io.ByteArrayOutputStream; |
|
40 |
import java.io.ObjectOutputStream; |
|
41 |
import java.lang.reflect.Field; |
|
42 |
import sun.rmi.server.MarshalInputStream; |
|
43 |
||
44 |
/** |
|
45 |
* usage: UseCodebaseOnlyDefault expected |
|
46 |
* |
|
47 |
* 'expected' is the expected value of useCodebaseOnly, which |
|
48 |
* must be "true" or "false". |
|
49 |
*/ |
|
50 |
public class UseCodebaseOnlyDefault { |
|
51 |
static final String USAGE = "usage: UseCodebaseOnlyDefault boolean"; |
|
52 |
static final String PROPNAME = "java.rmi.server.useCodebaseOnly"; |
|
53 |
||
54 |
/** |
|
55 |
* Gets the actual useCodebaseOnly value by creating an instance |
|
56 |
* of MarshalInputStream and reflecting on the useCodebaseOnly field. |
|
57 |
*/ |
|
58 |
static boolean getActualValue() throws Exception { |
|
59 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
60 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
|
61 |
oos.writeObject("foo"); |
|
62 |
oos.close(); |
|
63 |
||
64 |
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); |
|
65 |
MarshalInputStream mis = new MarshalInputStream(bais); |
|
66 |
||
67 |
Field f = MarshalInputStream.class.getDeclaredField("useCodebaseOnly"); |
|
68 |
f.setAccessible(true); |
|
69 |
return f.getBoolean(mis); |
|
70 |
} |
|
71 |
||
72 |
public static void main(String[] args) throws Exception { |
|
73 |
if (args.length != 1) { |
|
74 |
throw new IllegalArgumentException(USAGE); |
|
75 |
} |
|
76 |
||
77 |
boolean expected; |
|
78 |
if (args[0].equals("true")) { |
|
79 |
expected = true; |
|
80 |
} else if (args[0].equals("false")) { |
|
81 |
expected = false; |
|
82 |
} else { |
|
83 |
throw new IllegalArgumentException(USAGE); |
|
84 |
} |
|
85 |
System.out.println("expected = " + expected); |
|
86 |
||
87 |
String prop = System.getProperty(PROPNAME); |
|
88 |
System.out.print("Property " + PROPNAME); |
|
89 |
if (prop == null) { |
|
90 |
System.out.println(" is not set"); |
|
91 |
} else { |
|
92 |
System.out.println(" = '" + prop + "'"); |
|
93 |
} |
|
94 |
||
95 |
boolean actual = getActualValue(); |
|
96 |
System.out.println("actual = " + actual); |
|
97 |
||
98 |
if (expected != actual) |
|
99 |
throw new AssertionError("actual does not match expected value"); |
|
100 |
} |
|
101 |
} |