Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8359130

JMXServiceURL should require an explicit protocol

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • core-svc
    • None
    • behavioral
    • minimal
    • Behaviour change in a very niche feature.
    • Java API
    • SE

      Summary

      javax.management.remote.JMXServiceURL can be constructed with a String or individual parameters. The String constructor requires that a protocol name is included, while the constructors with parameters default to setting the protocol as jmxmp if missing.

      All constructors should behave the same way, and require a protocol. This will remove the historic oddity that JMXServiceURL defaults to jmxmp if a null protocol is specified.

      Problem

      All javax.management.remote.JMXServiceURL constructors do not behave the same way regarding specifying the protocol.

      For some constructors to default to jmxmp if a null protocol is specified is very odd, considering jmxmp was never part of the JDK, and only exists in the historical JMX optional reference implementation.

      Solution

      Do not default to jmxmp when the protocol is missing for any constructor. Always require that a protocol is specified.

      Specification

      src/java.management/share/classes/javax/management/remote/JMXServiceURL.java:

      Two constructors are updated to say that they do not have a default value for protocol, and null protocol is added to the reasons for throwing MalformedURLException:

      @@ -238,8 +238,8 @@ public JMXServiceURL(String serviceURL) throws MalformedURLException {
            * {@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 JMXServiceURL(String serviceURL) throws MalformedURLException {
            * @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 JMXServiceURL(String protocol, String host, int port)
           /**
            * <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 JMXServiceURL(String protocol, String host, int port)
            * @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)

      While here, these two files can benefit from removing the mention of JMXMP in their API docs. It is used as an example and has no impact:

      src/java.management/share/classes/javax/management/remote/JMXConnectorServerMBean.java src/java.management/share/classes/javax/management/remote/JMXConnectorServer.java

            * <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>

      Github reference: https://git.openjdk.org/jdk/pull/25674

            kevinw Kevin Walls
            kevinw Kevin Walls
            Serguei Spitsyn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: