Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8256242

Module::getPackages on an unnamed module may return packages that are in a named module

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 16
    • core-libs
    • None
    • behavioral
    • low
    • Hide
      It's expected that `Module::getPackages` is rarely used. There is no report
      of this method returning an incorrect set of packages for an unnamed module
       in particular if this module is defined in the system class loader which defines
      many other JDK modules.
      Show
      It's expected that `Module::getPackages` is rarely used. There is no report of this method returning an incorrect set of packages for an unnamed module  in particular if this module is defined in the system class loader which defines many other JDK modules.
    • Java API
    • SE

      Summary

      Fix Module::getPackages spec to return the packages that have been defined for this module if it's an unnamed module.

      Problem

      The current spec of Module::getPackages specifies that: For unnamed modules, this method is the equivalent to invoking the {@link ClassLoader#getDefinedPackages() getDefinedPackages} method of this module's class loader and returning the set of package names.

      The return packages include the packages defined in the unnamed module and any other named module of this module's class loader. This is a spec and implementation bug because this method expects to return the packages belonging to this module.

      Solution

      Change the spec and implementation to return the defined packages in this module if it's an unnamed module.

      Specification

      --- a/src/java.base/share/classes/java/lang/Module.java
      +++ b/src/java.base/share/classes/java/lang/Module.java
      @@ -1077,9 +1077,9 @@ public final class Module implements AnnotatedElement {
            * <p> For named modules, the returned set contains an element for each
            * package in the module. </p>
            *
      -     * <p> For unnamed modules, this method is the equivalent to invoking the
      -     * {@link ClassLoader#getDefinedPackages() getDefinedPackages} method of
      -     * this module's class loader and returning the set of package names. </p>
      +     * <p> For unnamed modules, the returned set contains an element for
      +     * each package that {@link ClassLoader#getDefinedPackages() has been defined}
      +     * in the unnamed module.</p>
            *
            * @return the set of the package names of the packages in this module
            */

            mchung Mandy Chung
            alanb Alan Bateman
            Alan Bateman, Chris Hegarty
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: