Review Request: loading JCE providers using ServiceLoader
Alan Bateman
Alan.Bateman at oracle.com
Sun Aug 12 13:10:48 PDT 2012
On 09/08/2012 16:14, Sean Mullan wrote:
> Please review the 2nd webrev for my code changes to enable JCE providers to be
> registered and loaded as services using the ServiceLoader API:
>
> http://cr.openjdk.java.net/~mullan/jigsaw/webrevs/jce-service/webrev.01/
>
> See [1] for previous discussion.
>
> The main change is that in module-mode all available Providers are now
> agressively loaded and cached. The code for loading providers has also been
> restructured. There is a new Providers.ProviderLoader interface and subclass
> implementations for module and classpath mode.
>
> There are a few outstanding issues that should be looked at later. I will create
> a new bug so that we don't lose track of them, but briefly:
>
> 1. ServiceLoaders don't support a configured preference order for providers
> 2. Cannot pass an optional argument (ex: a config file) to a provider via
> ServiceLoader
> 3. Cannot have more than one instance of a provider (ex: the SunPKCS11 Provider
> allows multiple instances with different config files)
> 4. ServiceLoaderConfigurationError does not retain which provider generated the
> error
>
> I've worked around some of these in the code, but none is a perfect solution.
> However, in the interests of moving forward, I would like to leave these as open
> issues for now.
>
> Thanks,
> Sean
>
> [1] http://mail.openjdk.java.net/pipermail/jigsaw-dev/2012-July/003053.html
I think this looks much cleaner. One thing that isn't completely clear
to me is what happens to security providers that are installed but not
registered in the java.security file. If I read the code correctly then
they will be loaded but just ignored because the lookup is keyed on
class name.
I looked at the exception handling (which is a hack, as you noted in the
comments). I'm not so sure that having SCE define a method to get the
class name of the service is the right thing to do. I think the real
issue is that the listing the provider class names in the java.security
file is getting in the way, forcing you to eagerly load all the
providers so that you can match up the class name and saving any
exceptions thrown during the loading so that you can throw them later.
So I think what you have is fine for now but it will need to be
re-examined, maybe after there is a way to configure the order of the
service provider modules. If that was a way to do this and we could
somehow migrate away listing the providers by class name in the
java.security file then it would be a lot cleaner.
Just in passing, is UOE documented anywhere? From the javadoc it looks
like ProviderException is the only exception that may be thrown.
-Alan.
More information about the jigsaw-dev
mailing list