-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
low
-
-
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
*/
- csr of
-
JDK-8256063 Module::getPackages on an unnamed module may return packages that are in a named module
- Resolved