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

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 16
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      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.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      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
            */

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: