{"record":{"id":"f6d618b24da8a368","repo":"SonarSource/sonarqube","slug":"can-not-register-mbean","errorCode":null,"errorMessage":"Can not register MBean [","messagePattern":"Can not register MBean \\[","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-process/src/main/java/org/sonar/process/Jmx.java","lineNumber":49,"sourceCode":"/**\n * JMX utilities to register MBeans to JMX server\n */\npublic class Jmx {\n\n  private Jmx() {\n    // only statics\n  }\n\n  /**\n   * Register a MBean to JMX server\n   */\n  public static void register(String name, Object instance) {\n    try {\n      Class<Object> mbeanInterface = guessMBeanInterface(instance);\n      ManagementFactory.getPlatformMBeanServer().registerMBean(new StandardMBean(instance, mbeanInterface), new ObjectName(name));\n\n    } catch (MalformedObjectNameException | NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {\n      throw new IllegalStateException(\"Can not register MBean [\" + name + \"]\", e);\n    }\n  }\n\n  /**\n   * MBeans have multiple conventions, including:\n   * 1. name of interface is suffixed by \"MBean\"\n   * 2. name of implementation is the name of the interface without \"MBean\"\n   * 3. implementation and interface must be in the same package\n   * To avoid the last convention, we wrap the mbean within a StandardMBean. That\n   * requires to find the related interface.\n   */\n\n  private static Class<Object> guessMBeanInterface(Object instance) {\n    Class<Object> mbeanInterface = null;\n    Class<Object>[] interfaces = (Class<Object>[])instance.getClass().getInterfaces();\n    for (Class<Object> anInterface : interfaces) {\n      if (anInterface.getName().endsWith(\"MBean\")) {\n        mbeanInterface = anInterface;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-process/src/main/java/org/sonar/process/Jmx.java#L31-L67","documentation":"Jmx.register wraps any JMX registration failure (malformed ObjectName, non-compliant MBean, already-registered name, registration rejected) into an IllegalStateException. The MBean could not be registered with the platform MBean server.","triggerScenarios":"register(name, instance) with a name that is not a valid ObjectName, an object with no valid MBean interface, or a name already bound in the MBean server.","commonSituations":"Name missing required domain or key property (e.g. missing key in 'type='); two components trying to register the same MBean name; class missing a suitable interface.","solutions":["Check the ObjectName string follows 'domain:key=value' syntax","Check the name is not already registered (or unregister it first)","Ensure the instance implements a public interface whose name ends in MBean","Inspect the wrapped cause exception for the exact JMX failure"],"exampleFix":"// before\nJmx.register(\"SonarWatchdog\", watchdog);\n// after\nJmx.register(\"org.sonar:type=Watchdog\", watchdog);","handlingStrategy":"try-catch","validationCode":"try { new ObjectName(name); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(\"bad ObjectName: \" + name, e); }","typeGuard":null,"tryCatchPattern":"try { Jmx.register(name, instance); } catch (IllegalStateException e) { LOGGER.warn(\"MBean {} not registered\", name, e); }","preventionTips":["Use valid ObjectName syntax 'domain:key=value'","Use unique, component-scoped MBean names","Only pass objects implementing a public *MBean interface"],"tags":["jmx","mbean","monitoring"],"backgroundTag":"module-init-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}