aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephan Siano (JIRA)" <>
Subject [jira] Commented: (ARIES-572) NamingException in JMXConnectionFactory.connect() calls with JMX over RMI calls
Date Fri, 11 Feb 2011 13:38:57 GMT


Stephan Siano commented on ARIES-572:

After giving the issue another thought and consulting the javax.spi.naming.ObjectFactory javadoc
I guess that the code should not only catch NamingException but all Exceptions and do a break
as the exception handler, because the javadoc says:
"Throws: Exception - if this object factory encountered an exception while attempting to create
an object, and no other object factories are to be tried.". At least the code cannot rely
on the implementation just returning null because "If obj is of any other type [than null,
an URL or an array of URL objects], the behavior of getObjectInstance() is determined by the
context factory implementation. ", so it is probably legal to throw an exception here as the
com.sun.jndi.url.rmi.rmiURLContextFactory does.

I still don't understand why the ObjectFactoryHelper.getObjectInstance() gets called at all
with a valid RMI proxy instance as the first parameter, but if the Exception is caught the
code will proceed with the instance it already has, which works fine.

> NamingException in JMXConnectionFactory.connect() calls with JMX over RMI calls
> -------------------------------------------------------------------------------
>                 Key: ARIES-572
>                 URL:
>             Project: Aries
>          Issue Type: Bug
>          Components: JNDI
>    Affects Versions: 0.3, 0.4
>            Reporter: Stephan Siano
> I get a NamingException with the following bundle activator if aries-jndi is present
(I tried the current 0.4-SNAPSOT and 0.3):
> public class Activator implements BundleActivator {
> 	@Override
> 	public void start(BundleContext bundleContext) throws Exception {
> 		Map<String, Object> env = new HashMap<String, Object>();
> 		env.put("osgi.service.jndi.bundleContext", bundleContext);
> 		JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1717/jmxrmi"),
> 	}
> 	@Override
> 	public void stop(BundleContext arg0) throws Exception {
> 	}
> }
> The bundle context in the environment is necessary to work around another issue.
> The NamingException is thrown by com.sun.jndi.url.rmi.rmiURLContextFactory.getObjectInstance()
if the first parameter is not an URL. This method is called from org.apache.aries.jndi.ObjectFactoryHelper.getObjectInstanceUsingObjectFactories().
This method iterates over all registered ObjectFactories to check if there is a better implementation
than the one provided in the first argument, however if it comes to Sun's object factory the
NamingException occurs (and will be propagated upwards) even though the proxy object that
is already there is actually fine.
> Therefore I would propose the following change:
> Index: src/main/java/org/apache/aries/jndi/
> ===================================================================
> --- src/main/java/org/apache/aries/jndi/	(revision 1068918)
> +++ src/main/java/org/apache/aries/jndi/	(working copy)
> @@ -115,6 +115,7 @@
>                      try {
>                          result = factory.getObjectInstance(obj, name, nameCtx, environment);
> +                    } catch (NamingException e) {
>                      } finally {
>                          callerContext.ungetService(ref);
>                      }
> The empty catch block is needed because obviously some ObjectFactories throw a NamingException
instead of returning null in some circumstances.

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message