Review Request: loading JCE providers using ServiceLoader

Paul Sandoz paul.sandoz at oracle.com
Wed Aug 1 15:04:58 PDT 2012


Hi Sean,

Unfortunately there is no ability to to ask ServiceLoader to "jump to" a specific service provider class and instantiate, if present, or just iterate through the class names, nor is there currently a way to get the offending class name from SCE. So you may have to resort to doing something unpleasant with the SCE message.

However, i think there may be a more serious problem. You are caching a reference to ServiceLoader, and that will cache the service instances that were successfully instantiated via iteration. Basically you may get an SCE on the first iteration but you will not get an SCE on the second and subsequent iterations.

Paul.

On Aug 1, 2012, at 1:12 PM, Sean Mullan <sean.mullan at oracle.com> wrote:

> I discovered another issue with respect to using a ServiceLoader to load JCE providers. In our current JDK implementation, if you try to load a Provider using Security.getProvider(String) and the Provider's ctor throws a ProviderException, this gets passed through to the caller.
> 
> This type of behavior is difficult to preserve when using a ServiceLoader. I can catch a ServiceConfigurationError and check the cause to see if is an instanceof ProviderException, but I don't necessarily know what Provider threw the exception. Do you see the problem? If the ServiceConfigurationError also captured the name of the class, then I could figure out which Provider was throwing the exception and pass it back through.
> 
> Thanks,
> Sean
> 




More information about the jigsaw-dev mailing list