0 Replies Latest reply on Jul 23, 2008 9:53 AM by Robert Buck

    MBeanServer.getDefaultDomain returns null

    Robert Buck Newbie

      When JBoss is run with these additional options, to expose JBoss MBean's in JConsole, application code that looks up the MBeanServer gets an NPE.

      When one starts JBoss with the following options:

      set JAVA_OPTS=%JAVA_OPTS% -Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl
      set JAVA_OPTS=%JAVA_OPTS% -Djboss.platform.mbeanserver
      set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote
      


      which is detailed here on your site:

      http://wiki.jboss.org/wiki/JBossMBeansInJConsole

      Calls to server.getDefaultDomain() returns null when should not have. Here is my applications JMX helper:

      public static MBeanServer getDefaultMBeanServer() {
       // detects if we are running from within jboss...
       MBeanServer server = findMBeanServer("jboss");
      
       // otherwise falls back to the default platform mbean server...
       if (server == null) {
       server = ManagementFactory.getPlatformMBeanServer();
       }
       return server;
       }
      
       private static MBeanServer findMBeanServer(String agentId) {
       List servers = MBeanServerFactory.findMBeanServer(null);
       if (servers != null && servers.size() > 0) {
       for (Object object : servers) {
       MBeanServer server = (MBeanServer) object;
       if (server.getDefaultDomain().equals(agentId)) {
       return server;
       }
       }
       }
       return null;
       }
      


      There was a related thread that never got an answer back in 2007:

      http://lists.jboss.org/pipermail/jboss-user/2007-February/038880.html

      This looks like a defect in JBoss. If so, what workaround exists for it?