author | serb |
Tue, 12 Nov 2013 20:24:25 +0400 | |
changeset 21596 | 0e3a39f29dbc |
parent 14917 | bf08557604f8 |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4943248 |
|
27 |
* @summary Tests that NullPointerException is thrown when listener is null. |
|
28 |
* @author Daniel Fuchs |
|
29 |
* @run clean ConnectionListenerNullTest |
|
30 |
* @run build ConnectionListenerNullTest |
|
31 |
* @run main ConnectionListenerNullTest |
|
32 |
*/ |
|
33 |
import javax.management.remote.JMXConnector; |
|
34 |
import javax.management.remote.JMXServiceURL; |
|
35 |
import javax.management.remote.JMXConnectorFactory; |
|
36 |
import javax.management.Notification; |
|
37 |
import javax.management.NotificationFilter; |
|
38 |
import javax.management.NotificationListener; |
|
39 |
import java.util.Map; |
|
40 |
public class ConnectionListenerNullTest { |
|
41 |
||
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
42 |
static boolean isPresent(String cn) { |
2 | 43 |
try { |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
44 |
Class.forName(cn); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
45 |
return true; |
2 | 46 |
} catch (ClassNotFoundException x) { |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
47 |
return false; |
2 | 48 |
} |
49 |
} |
|
50 |
||
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
51 |
public static int test(String... urls) { |
2 | 52 |
int errCount = 0; |
53 |
for (int i=0;i<urls.length;i++) { |
|
54 |
try { |
|
55 |
final JMXServiceURL url = new JMXServiceURL(urls[i]); |
|
56 |
final JMXConnector c = |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
57 |
JMXConnectorFactory.newJMXConnector(url,(Map<String,String>)null); |
2 | 58 |
final NotificationListener nl = null; |
59 |
final NotificationFilter nf = null; |
|
60 |
final Object h = null; |
|
61 |
System.out.println("Testing " + c.getClass().getName()); |
|
62 |
try { |
|
63 |
System.out.println( |
|
64 |
"addConnectionNotificationListener(null,null,null)"); |
|
65 |
c.addConnectionNotificationListener(nl,nf,h); |
|
66 |
throw new AssertionError("No exception raised"); |
|
67 |
} catch (NullPointerException npe) { |
|
68 |
// OK. |
|
69 |
} |
|
70 |
final NotificationListener listener = new |
|
71 |
NotificationListener() { |
|
72 |
public void handleNotification(Notification notification, |
|
73 |
Object handback) { |
|
74 |
} |
|
75 |
}; |
|
76 |
c.addConnectionNotificationListener(listener,nf,h); |
|
77 |
try { |
|
78 |
System.out.println( |
|
79 |
"removeConnectionNotificationListener(null)"); |
|
80 |
c.removeConnectionNotificationListener(nl); |
|
81 |
throw new AssertionError("No exception raised"); |
|
82 |
} catch (NullPointerException npe) { |
|
83 |
// OK. |
|
84 |
} |
|
85 |
try { |
|
86 |
System.out.println( |
|
87 |
"removeConnectionNotificationListener(null,null,null)"); |
|
88 |
c.removeConnectionNotificationListener(nl,nf,h); |
|
89 |
throw new AssertionError("No exception raised"); |
|
90 |
} catch (NullPointerException npe) { |
|
91 |
// OK. |
|
92 |
} |
|
93 |
c.removeConnectionNotificationListener(listener); |
|
94 |
System.out.println(c.getClass().getName() + |
|
95 |
" successfully tested."); |
|
96 |
} catch (Exception x) { |
|
97 |
System.err.println("Unexpected exception for " + |
|
98 |
urls[i] + ": " + x); |
|
99 |
x.printStackTrace(); |
|
100 |
errCount++; |
|
101 |
} catch (AssertionError e) { |
|
102 |
System.err.println("Unexpected assertion error for " + |
|
103 |
urls[i] + ": " + e); |
|
104 |
e.printStackTrace(); |
|
105 |
errCount++; |
|
106 |
} |
|
107 |
} |
|
108 |
return errCount; |
|
109 |
} |
|
110 |
||
111 |
public static void main(String args[]) { |
|
112 |
int errCount = 0; |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
113 |
|
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
114 |
// mandatory |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
115 |
errCount += test("service:jmx:rmi://"); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
116 |
|
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
117 |
// optional |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
118 |
if (isPresent("javax.management.remote.rmi._RMIConnectionImpl_Tie")) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
119 |
errCount += test("service:jmx:iiop://"); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
120 |
if (isPresent("javax.management.remote.generic.GenericConnector")) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
121 |
errCount += test("service:jmx:jmxmp://"); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
122 |
|
2 | 123 |
if (errCount > 0) { |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
124 |
throw new RuntimeException("ConnectionListenerNullTest failed: " + |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
125 |
errCount + " error(s) reported."); |
2 | 126 |
} |
127 |
System.out.println("ConnectionListenerNullTest passed."); |
|
128 |
} |
|
129 |
} |