Example code in JDK8 requiring change for modular function

Alan Bateman Alan.Bateman at oracle.com
Mon May 7 01:39:09 PDT 2012


On 07/05/2012 09:06, Paul Sandoz wrote:
> :
>
>> Implementation-wise it will require the base module to have "requires optional service java.nio.file.spi.FileTypeDetector" in its module declaration and the ServiceLoader usage changed as the legacy system class loader notion doesn't make sense when running with modules.
> FWIW i verified that is the case today in Jigsaw. Do the generated module-info.java files contain all known providers, or is there still some work to do here?
Non-static dependencies are a bit fragile at this point, and will be 
until we check in the module-info sources. For now it requires making 
sure that jdk/make/modules/jdk.depconfig is up to date. In this case the 
issue is that it's in jdk.depconfig as:

@Provider(optional)
   java.nio.file.Files$DefaultFileTypeDetectorHolder -> 
META-INF/services/java.nio.file.spi.FileTypeDetector

but that's not the right inner class name anymore.  Apologies about 
that, I fixed lots of these when adding the services support but I 
missed this one.

> The main concern i have with this example is the caching of the service provider implementations. It is something we will have to revisit.
>
This specific case was never intended to be dynamic, it's specified to 
maintain a system-wide list of file type detectors. But as you bring up 
caching then one observation is that as the user of the service is 
linked with the service providers at configuration time then caching by 
the user of ServiceLoader isn't going to change the performance, meaning 
there isn't really any need for this code to cache the providers when 
running with modules. I guess the concern you have is the container 
managed application that comes with their own file type detector, that 
scenario would require consideration.

-Alan




More information about the jigsaw-dev mailing list