From 9652ae9a8d48924a90d25e9daffcdb7f582ff503 Mon Sep 17 00:00:00 2001
From: Kevin Walls
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).
+ * stubs. The RMI Connector does so. * *The default implementation of this method uses {@link * #getAddress} and {@link JMXConnectorFactory} to generate the diff --git a/src/java.management/share/classes/javax/management/remote/JMXConnectorServerMBean.java b/src/java.management/share/classes/javax/management/remote/JMXConnectorServerMBean.java index fdc7fa5b3a1..4d8602bb81b 100644 --- a/src/java.management/share/classes/javax/management/remote/JMXConnectorServerMBean.java +++ b/src/java.management/share/classes/javax/management/remote/JMXConnectorServerMBean.java @@ -186,8 +186,7 @@ public interface JMXConnectorServerMBean { * one new connection to this connector server.
* *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).
+ * stubs. The RMI Connector does so. * * @param env client connection parameters of the same sort that * can be provided to {@link JMXConnector#connect(Map) diff --git a/src/java.management/share/classes/javax/management/remote/JMXServiceURL.java b/src/java.management/share/classes/javax/management/remote/JMXServiceURL.java index b6c2860b9cd..da47f7a1eda 100644 --- a/src/java.management/share/classes/javax/management/remote/JMXServiceURL.java +++ b/src/java.management/share/classes/javax/management/remote/JMXServiceURL.java @@ -238,8 +238,8 @@ public class JMXServiceURL implements Serializable { * {@link #JMXServiceURL(String, String, int, String) * JMXServiceURL(protocol, host, port, null)}. * - * @param protocol the protocol part of the URL. If null, defaults - * tojmxmp.
+ * @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 host is null and it
* is not possible to find the local host name, or if
- * port is negative.
+ * port 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 {
/**
* Constructs a JMXServiceURL with the given parts.
*
- * @param protocol the protocol part of the URL. If null, defaults
- * to jmxmp.
+ * @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 host is null and it
* is not possible to find the local host name, or if
- * port is negative.
+ * port 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 {
diff --git a/test/jdk/javax/management/remote/mandatory/connection/JMXServiceURLProtocol.java b/test/jdk/javax/management/remote/mandatory/connection/JMXServiceURLProtocol.java
new file mode 100644
index 00000000000..2db6be4efe4
--- /dev/null
+++ b/test/jdk/javax/management/remote/mandatory/connection/JMXServiceURLProtocol.java
@@ -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);
+ }
+
+ }
+}