mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8347114: JMXServiceURL should require an explicit protocol
Reviewed-by: dfuchs, sspitsyn
This commit is contained in:
parent
59460ff700
commit
9652ae9a8d
@ -133,8 +133,7 @@ public abstract class JMXConnectorServer
|
||||
* one new connection to this connector server.</p>
|
||||
*
|
||||
* <p>A given connector need not support the generation of client
|
||||
* stubs. However, the connectors specified by the JMX Remote API do
|
||||
* (JMXMP Connector and RMI Connector).</p>
|
||||
* stubs. The RMI Connector does so.</p>
|
||||
*
|
||||
* <p>The default implementation of this method uses {@link
|
||||
* #getAddress} and {@link JMXConnectorFactory} to generate the
|
||||
|
||||
@ -186,8 +186,7 @@ public interface JMXConnectorServerMBean {
|
||||
* one new connection to this connector server.</p>
|
||||
*
|
||||
* <p>A given connector need not support the generation of client
|
||||
* stubs. However, the connectors specified by the JMX Remote API do
|
||||
* (JMXMP Connector and RMI Connector).</p>
|
||||
* stubs. The RMI Connector does so.</p>
|
||||
*
|
||||
* @param env client connection parameters of the same sort that
|
||||
* can be provided to {@link JMXConnector#connect(Map)
|
||||
|
||||
@ -238,8 +238,8 @@ public class JMXServiceURL implements Serializable {
|
||||
* {@link #JMXServiceURL(String, String, int, String)
|
||||
* JMXServiceURL(protocol, host, port, null)}.</p>
|
||||
*
|
||||
* @param protocol the protocol part of the URL. If null, defaults
|
||||
* to <code>jmxmp</code>.
|
||||
* @param protocol the protocol part of the URL. Must be specified,
|
||||
* there is no default.
|
||||
*
|
||||
* @param host the host part of the URL. If host is null and if
|
||||
* local host name can be resolved to an IP, then host defaults
|
||||
@ -255,7 +255,7 @@ public class JMXServiceURL implements Serializable {
|
||||
* @exception MalformedURLException if one of the parts is
|
||||
* syntactically incorrect, or if <code>host</code> is null and it
|
||||
* is not possible to find the local host name, or if
|
||||
* <code>port</code> is negative.
|
||||
* <code>port</code> is negative, or if protocol is null.
|
||||
*/
|
||||
public JMXServiceURL(String protocol, String host, int port)
|
||||
throws MalformedURLException {
|
||||
@ -265,8 +265,8 @@ public class JMXServiceURL implements Serializable {
|
||||
/**
|
||||
* <p>Constructs a <code>JMXServiceURL</code> with the given parts.
|
||||
*
|
||||
* @param protocol the protocol part of the URL. If null, defaults
|
||||
* to <code>jmxmp</code>.
|
||||
* @param protocol the protocol part of the URL. Must be specified,
|
||||
* there is no default.
|
||||
*
|
||||
* @param host the host part of the URL. If host is null and if
|
||||
* local host name can be resolved to an IP, then host defaults
|
||||
@ -285,14 +285,14 @@ public class JMXServiceURL implements Serializable {
|
||||
* @exception MalformedURLException if one of the parts is
|
||||
* syntactically incorrect, or if <code>host</code> is null and it
|
||||
* is not possible to find the local host name, or if
|
||||
* <code>port</code> is negative.
|
||||
* <code>port</code> is negative, or if protocol is null.
|
||||
*/
|
||||
public JMXServiceURL(String protocol, String host, int port,
|
||||
String urlPath)
|
||||
throws MalformedURLException {
|
||||
if (protocol == null)
|
||||
protocol = "jmxmp";
|
||||
|
||||
if (protocol == null) {
|
||||
throw new MalformedURLException("Misssing protocol name");
|
||||
}
|
||||
if (host == null) {
|
||||
InetAddress local;
|
||||
try {
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8347114
|
||||
* @summary Test JMXServiceURL does not accept a null protocol
|
||||
*
|
||||
* @run main JMXServiceURLProtocol
|
||||
*/
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
public class JMXServiceURLProtocol {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
try {
|
||||
JMXServiceURL u = new JMXServiceURL("service:jmx:://");
|
||||
String proto = u.getProtocol();
|
||||
System.out.println("JMXServiceURL(String) with null protocol gets: " + u + " protocol: " + proto);
|
||||
throw new RuntimeException("JMXServiceURL created using null protocol: " + u);
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("JMXServiceURL with null protocol causes expected: " + e);
|
||||
}
|
||||
|
||||
try {
|
||||
JMXServiceURL u = new JMXServiceURL(null, "localhost", 1234);
|
||||
String proto = u.getProtocol();
|
||||
System.out.println("JMXServiceURL(params) with null protocol gets: " + u + " protocol: " + proto);
|
||||
throw new RuntimeException("JMXServiceURL created using null protocol: " + u);
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("JMXServiceURL with null protocol causes expected: " + e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user