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

Reviewed-by: alanb, chegar
This commit is contained in:
Mandy Chung 2020-11-13 00:32:29 +00:00
parent 531c56ea65
commit dff26a489d
4 changed files with 122 additions and 5 deletions

View file

@ -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
*/
@ -1094,11 +1094,11 @@ public final class Module implements AnnotatedElement {
} else {
packages = loader.packages();
}
return packages.map(Package::getName).collect(Collectors.toSet());
return packages.filter(p -> p.module() == this)
.map(Package::getName).collect(Collectors.toSet());
}
}
// -- creating Module objects --
/**