title: How do I avoid this NullPointerException when connecting remotely to a JBoss AS via JMX from VisualVM?
body: <h3>Problem:</h3>
  
  <p>When I connect via VisualVM and supply the correct credentials, the program seems to wait a bit (either processing or waiting for the connection), then errors out with this an exception.  The connection does not seem to get added correctly after this exception is throw:</p>
  
  <pre><code>java.lang.NullPointerException: Illegal null argument
      at javax.management.remote.JMXConnectionNotification.&lt;init&gt;(JMXConnectionNotification.java:152)
      at javax.management.remote.rmi.RMIConnector$RMIClientCommunicatorAdmin.gotIOException(RMIConnector.java:1444)
      at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.isInstanceOf(RMIConnector.java:1062)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sun.tools.visualvm.jmx.impl.JmxModelImpl$CheckerInvocationHandler.invoke(JmxModelImpl.java:598)
      at $Proxy7.isInstanceOf(Unknown Source)
      at java.lang.management.ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.java:616)
      at com.sun.tools.visualvm.tools.jmx.JvmMXBeansFactory$JvmMXBeansImpl.getMXBean(JvmMXBeansFactory.java:383)
      at com.sun.tools.visualvm.tools.jmx.JvmMXBeansFactory$JvmMXBeansImpl.getRuntimeMXBean(JvmMXBeansFactory.java:356)
      at com.sun.tools.visualvm.jmx.impl.JmxApplication.getPid(JmxApplication.java:84)
      at com.sun.tools.visualvm.jvmstat.JvmstatModelProvider.getMonitoredVm(JvmstatModelProvider.java:49)
      at com.sun.tools.visualvm.jvmstat.JvmstatModelProvider.createModelFor(JvmstatModelProvider.java:71)
      at com.sun.tools.visualvm.jvmstat.JvmstatModelProvider.createModelFor(JvmstatModelProvider.java:45)
      at com.sun.tools.visualvm.core.model.ModelFactory.getModel(ModelFactory.java:111)
      at com.sun.tools.visualvm.tools.jvmstat.JvmstatModelFactory.getJvmstatFor(JvmstatModelFactory.java:65)
      at com.sun.tools.visualvm.jvm.JRockitJvmProvider.createModelFor(JRockitJvmProvider.java:49)
      at com.sun.tools.visualvm.jvm.JRockitJvmProvider.createModelFor(JRockitJvmProvider.java:42)
      at com.sun.tools.visualvm.core.model.ModelFactory.getModel(ModelFactory.java:111)
      at com.sun.tools.visualvm.application.jvm.JvmFactory.getJVMFor(JvmFactory.java:65)
      at com.sun.tools.visualvm.jmx.impl.JmxApplicationProvider.addJmxApplication(JmxApplicationProvider.java:292)
      at com.sun.tools.visualvm.jmx.impl.JmxApplicationProvider.access$100(JmxApplicationProvider.java:73)
      at com.sun.tools.visualvm.jmx.impl.JmxApplicationProvider$3$1.run(JmxApplicationProvider.java:408)
      at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1424)
  [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1968)
  </code></pre>
  
  <h3>Background:</h3>
  
  <p>I am using VisualVM to do some simple profiling work.  I am running jboss-4.2.2.GA on Windows.</p>
  
  <p>In my <code>run.bat</code> file I have:</p>
  
  <pre><code>set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=&lt;myport&gt;
  set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.local.only=false
  set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.ssl=false
  </code></pre>
  
  <p>In the JMX password file I created, I have enabled a role with read only access, and have made sure read access is set appropriately on that file.</p>
  
  <p>I can connect to the server on <code>localhost:&lt;myport&gt;</code> via JMX.  The username and password match the role and password in my JMX password config file.  Using different credentials or a different password doesn't work, so this is definitely set up correctly.</p>
  
  <p>I have set up a general firewall exception in my domain for <code>java.exe</code>.  When I don't have this exception, I cannot connect at all to the server.  When I have it enabled, I can connect remotely to <code>myport</code> via telnet, and I get a password dialog when I try to connect remotely via VisualVM.</p>
  
  <p>I tried looking through the code referenced in the exception stack trace.  As far as I can tell, <code>connectionId</code> is probably <code>null</code> when constructing <code>JMXConnectionNotification</code>.  I can't tell why because I haven't bothered trying to run this in a debugger.</p>
  
  <h3>Is there anything I have configured incorrectly?  How do I get past this error?</h3>
  
  <hr>
  
  <p><em>Edit:</em></p>
  
  <p>I just tried connecting remotely with JConsole and I'm getting a totally different error:</p>
  
  <pre><code>java.rmi.ConnectException: Connection refused to host: 127.0.0.1;
  </code></pre>
  
  <p>I don't have any entries in my hosts file on the client machine, as some things on the net have suggested WRT this error.  Is this indicative of a different problem, or are they related?</p>