[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Question regarding class loader and getPackages()


equinox-dev-bounces@xxxxxxxxxxx wrote on 2008/06/02 08:58:36 AM:

> [image removed]

>
> [equinox-dev] Question regarding class loader and getPackages()

>
> Jan Stette

>
> to:

>
> Equinox development mailing list

>
> 2008/06/02 08:59 AM

>
> Sent by:

>
> equinox-dev-bounces@xxxxxxxxxxx

>
> Please respond to Equinox development mailing list <equinox-dev@xxxxxxxxxxx>

>
> I'm trying to call Package.getPackages() in some code in an OSGi
> bundle.  This calls into getPackages on the classloader, where I'm
> observing that:
>
> 1.  The call is not overridden in the Equinox classloader, so the
> default implementation in java.lang.ClassLoader is used.  Hence,
> only the bundle's own packages, and the system packages are returned.


I don't think imported packages should be listed since they are imported from other bundles.

> 2.  Only packages from which at least one class has been loaded are
> returned.  So, if a class hasn't been loaded from a given package,
> it won't be included in the returned list.
>
> I haven't found anything in the OSGi or Java language specs that
> specify this, but I expected all packages that the bundle
> classloader can see to be returned, something aking to the java doc
> description of Package.getPackages(): "Get all the packages
> currently known for the caller's ClassLoader instance. Those


The packages "currently known" are those for which at least one successful class load has occurred. There is no reliable or specified way for a class loader to "know" all the classes which it can successfully load.

> packages correspond to classes loaded via or accessible by name to that
> ClassLoader instance".  Which seems to suggest that both packages of
> classes that haven't been loaded yet, and packages imported by the
> bundle class loader should be listed.
>
> I realise that the Package Admin service is an alternative for this,
> but I'm surprised if these details can't be accessed through the
> class loader...
>
> Could anyone shed some light on this, please?
>
> Regards,
> Jan
> _______________________________________________
> equinox-dev mailing list
> equinox-dev@xxxxxxxxxxx
>
https://dev.eclipse.org/mailman/listinfo/equinox-dev

--

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the
OSGi Alliance
hargrave@xxxxxxxxxx

office: +1 386 848 1781
mobile: +1 386 848 3788