gcj & JMX
Gary Benson
gbenson@redhat.com
Thu Feb 15 11:15:00 GMT 2007
Andrew Haley wrote:
> Andrew John Hughes writes:
> > On Wed, 2007年02月14日 at 18:14 +0000, Andrew Haley wrote:
> > > With Classpath, none of this ever happens. Instead,
> > > gnu.javax.management.registerMBean(Object, ObjectName) does not
> > > call MBeanRegistration.preRegister() unless ObjectName == null.
> > >
> > > So, the preRegister method is never called.
> > >
> > > The spec for MBeanServer.registerMBean() says "If the object
> > > name given is null, the MBean must provide its own name by
> > > implementing the MBeanRegistration interface and returning the
> > > name from the preRegister method."
> > >
> > > I suspect, however, that if the MBean is implements the
> > > MBeanRegistration interface we should call the preRegister
> > > method regardless.
> > >
> > > I'm going to try it.
> >
> > Sounds good to me; I hope this fixes the problem. Maybe I
> > shouldn't stick to the specs and just go with common sense in
> > future... ;)
>> Maybe, although the spec doesn't actually say that regstration
> should only be done if there is no name, it just very strongly
> implies it. :-)
My reading of the various specs is that there's an unspoken assumption
that MBeans _may_ implement the MBeanRegistration interface _if_ they
want to do things before and after registration and/or deregistration
time, and that the spec for MBeanServer.registerMBean() merely changes
the "may" to a "must" for MBeans without a name.
Ok if I commit something like the attached patch?
Cheers,
Gary
-------------- next part --------------
Index: classpath/gnu/javax/management/Server.java
===================================================================
--- classpath/gnu/javax/management/Server.java (revision 121990)
+++ classpath/gnu/javax/management/Server.java (working copy)
@@ -1657,19 +1657,27 @@
MBeanRegistration register = null;
if (obj instanceof MBeanRegistration)
register = (MBeanRegistration) obj;
- if (name == null)
+ if (name == null && register == null)
{
- if (register == null)
- {
- RuntimeException e =
- new IllegalArgumentException("The name was null and " +
- "the bean does not implement " +
- "MBeanRegistration.");
- throw new RuntimeOperationsException(e);
- }
+ RuntimeException e =
+ new IllegalArgumentException("The name was null and " +
+ "the bean does not implement " +
+ "MBeanRegistration.");
+ throw new RuntimeOperationsException(e);
+ }
+ if (register != null)
+ {
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"));
More information about the Java
mailing list