Hi all,

MBeanServer.registerMBean() calls the MBean's preRegister method only
if the name given for the bean is null.  This commit makes it call the
preRegister method regardless of whether a name was supplied or not.

Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.9110
diff -u -r1.9110 ChangeLog
--- ChangeLog   15 Feb 2007 10:38:30 -0000      1.9110
+++ ChangeLog   15 Feb 2007 14:06:41 -0000
@@ -1,3 +1,10 @@
+2007-02-15  Gary Benson  <[EMAIL PROTECTED]>
+
+       * gnu/javax/management/Server.java
+       (registerMBean): Always register objects that implement the
+       MBeanRegistration interface, and check the name returned by
+       preRegister before using it.
+
 2007-02-15  Roman Kennke  <[EMAIL PROTECTED]>
 
        * java/nio/ByteOrder.java
Index: gnu/javax/management/Server.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/management/Server.java,v
retrieving revision 1.2
diff -u -r1.2 Server.java
--- gnu/javax/management/Server.java    4 Dec 2006 00:10:18 -0000       1.2
+++ gnu/javax/management/Server.java    15 Feb 2007 14:06:41 -0000
@@ -1657,19 +1657,27 @@
     MBeanRegistration register = null;
     if (obj instanceof MBeanRegistration)
       register = (MBeanRegistration) obj;
-    if (name == null)
+    if (name == null && register == null)
+      {
+       RuntimeException e =
+         new IllegalArgumentException("The name was null and " +
+                                      "the bean does not implement " +
+                                      "MBeanRegistration.");
+       throw new RuntimeOperationsException(e);
+      }
+    if (register != null)
       {
-       if (register == null)
-         {
-           RuntimeException e =
-             new IllegalArgumentException("The name was null and " +
-                                          "the bean does not implement " +
-                                          "MBeanRegistration.");
-           throw new RuntimeOperationsException(e);
-         }
        try
          {
-           name = register.preRegister(this, null);
+           name = register.preRegister(this, name);
+           if (name == null)
+             {
+               RuntimeException e =
+                 new NullPointerException("The name returned by " +
+                                          "MBeanRegistration.preRegister() " +
+                                          "was null");
+               throw e;
+             }
            if (sm != null)
              sm.checkPermission(new MBeanPermission(className, null, name,
                                                     "registerMBean"));

Reply via email to