JDK-2147943 : REGRESSION: JConsole connects to wrong MBean Server with URL service:jmx:rmi://localhost/jndi/...
  • Type: Backport
  • Backport of: JDK-6538179
  • Component: tools
  • Sub-Component: jconsole
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2007-03-24
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u2Fixed 7 b12Fixed
Description
Create an RMI server using code like the following:
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        LocateRegistry.createRegistry(9589);
        JMXServiceURL addr = new JMXServiceURL("rmi", null, 0, "/jndi/rmi://localhost:9589/jmx");
        RMIConnectorServer cs = new RMIConnectorServer(addr, env);
        ObjectName name = new ObjectName("connector:type=cserver,name=mycserver");
        server.registerMBean(cs, name);
        cs.start();

Then run jconsole using a URL like this:
    jconsole service:jmx:rmi://localhost/jndi/rmi://localhost:9589/jmx

The MBean Server you see is not the one created above.

This is a regression, because JConsole from JDK 5.0 does the right thing.  The bug is in JConsole, because if you create a connection programmatically using the same URL it works correctly.

This problem was reported on the SDN JMX forum by Robin Merckx and Erik Vaneylen; see <http://forum.java.sun.com/thread.jspa?messageID=9569129>.

Comments
SUGGESTED FIX ------- ProxyClient.java ------- 319c319 < if (hostName != null && hostName.equals("localhost") && port == 0) { --- > if (jmxUrl == null && hostName != null && hostName.equals("localhost") && port == 0) {
24-03-2007

WORK AROUND The first occurrence of "localhost" in a URL of this form is supposed to be ignored, so you can omit it. In other words, you can do jconsole service:jmx:rmi:///jndi/rmi://localhost:9589/jmx instead of jconsole service:jmx:rmi://localhost/jndi/rmi://localhost:9589/jmx and it works correctly.
24-03-2007

EVALUATION JConsole wrongly auto-connects to itself as if "localhost:0" had been entered in the Remote Process field when the entered JMXServiceURL is of the form: service:jmx:rmi://localhost/jndi/rmi://<host>:<port>/<server-name>
24-03-2007