ClassLoader.getPackages()

Mandy Chung mandy.chung at oracle.com
Mon May 21 10:28:08 PDT 2012



On 5/21/2012 8:55 AM, David M. Lloyd wrote:
> On 03/05/2012 04:44 PM, David M. Lloyd wrote:
>> The JavaDoc for ClassLoader.getPackages() says:
>>
>>   protected Package[] getPackages()
>>
>>   Returns all of the Packages defined by this class loader and its 
>> ancestors.
>>
>>   Returns:
>>     The array of Package objects defined by this ClassLoader
>>
>> The intention appears to be that the class loader returns all the
>> packages visible to it. However, it also assumes a strict parent/child
>> hierarchy of class loaders.
>>
>> My question is, how does the Jigsaw project interpret this method? Does
>> it return only Packages known to it and the parent class loader(s)
>> (which presumably includes only the "null" class loader)? Or does it
>> also include the Packages from its dependencies (i.e. the complete set
>> of visible Packages)?
>

What ClassLoader.getPackages() should do in modular world is an open 
issue [1] that requires further investigation and discussion.  As you 
said, Packages assume a strict parent-delegation hierachy.  Also it is 
tied with JAR manifest where the package information is specified.   One 
thought is that java.lang.Package will not be applicable in module mode 
and ClassLoader.getPackages() may just throw exception but the question 
would be how existing applications use java.lang.Package API and its 
implication.   Basically it's yet to determine what the existing 
ClassLoader methods means in module mode that makes sense and also 
requires evaluating its impact to existing applications.

Mandy
[1] http://openjdk.java.net/projects/jigsaw/doc/module-class-loading.pdf




More information about the jigsaw-dev mailing list