Issue: Modules can only open resources as streams

mark.reinhold at oracle.com mark.reinhold at oracle.com
Fri Mar 11 17:49:51 UTC 2016


2016/3/3 7:42 -0800, david.lloyd at redhat.com:
> Module.getResourceAsStream() is the only way a resource can be loaded 
> from a module.  This makes it impossible to do either of the following:
> 
> - Determine the size of a resource in advance of loading it
> - Determine the existence of a resource without opening it
> 
> Loading resources as java.net.URLs allowed these things to be done 
> (among other things), however it is also disadvantageous due to the 
> heavyweight nature of that class.
> 
> I had earlier come up with a simple patch [1], initially as a way to 
> address JDK-6865375 [2], which introduced the idea of a Resource class 
> that is associated with a ClassLoader, with a name, URL, size, and 
> stream factory method, which would also be a clean solution here (though 
> with the addition of a Module property as well since in Jigsaw they're 
> separate).
> 
> The idea is to put resources on a similar footing to classes, whereby 
> you can (if suitably permitted) acquire their class loaders just like 
> Class.getClassLoader() allows you to do for classes.  This also allows 
> things like ServiceLoader to load classes directly from the module which 
> contained the corresponding service descriptor.

New issue: http://openjdk.java.net/projects/jigsaw/spec/issues/#ResourceExistenceAndSize

- Mark


More information about the jpms-spec-experts mailing list