if (name != null) { ArrayList mbeanServers = MBeanServerFactory.findMBeanServer(null); MBeanServer mbeanServer = (MBeanServer) mbeanServers.get(0); try { ObjectName objectName = new ObjectName(name); mbeanServer.unregisterMBean(objectName); } catch (MalformedObjectNameException e) {  throw new CaptchaServiceException("Exception trying to create the object name under witch" + " the service is registered", e); } catch (InstanceNotFoundException e) {  throw new CaptchaServiceException("Exception trying to unregister the ImageCaptchaFilter from" + " the MBean server", e); } catch (MBeanRegistrationException e) {  throw new CaptchaServiceException("Exception trying to unregister the ImageCaptchaFilter from" + "the MBean server", e); } } else { throw new CaptchaServiceException("Service registration name can't be null"); }
    public static void unregisterFromMBeanServer(String name) {        if (name != null) {            ArrayList mbeanServers = MBeanServerFactory.findMBeanServer(null);            MBeanServer mbeanServer = (MBeanServer) mbeanServers.get(0);            try {                ObjectName objectName = new ObjectName(name);                mbeanServer.unregisterMBean(objectName);            } catch (MalformedObjectNameException e) {                // this should never happens                throw new CaptchaServiceException("Exception trying to create the object name under witch"                        + " the service is registered",                        e);            } catch (InstanceNotFoundException e) {                // this should never happens                throw new CaptchaServiceException("Exception trying to unregister the ImageCaptchaFilter from"                        + " the MBean server",                        e);            } catch (MBeanRegistrationException e) {                // this remains silent for the client                throw new CaptchaServiceException("Exception trying to unregister the ImageCaptchaFilter from"                        + "the MBean server",                        e);            }        } else {            throw new CaptchaServiceException("Service registration name can't be null");        }    }