< prev index next >
src/java.base/share/classes/java/lang/reflect/Module.java
Print this page
*** 557,567 ****
/**
* Returns {@code true} if this module exports or opens a package to
* the given module via its module declaration.
*/
! private boolean isStaticallyExportedOrOpen(String pn, Module other, boolean open) {
// package is open to everyone or <other>
Map<String, Set<Module>> openPackages = this.openPackages;
if (openPackages != null) {
Set<Module> targets = openPackages.get(pn);
if (targets != null) {
--- 557,567 ----
/**
* Returns {@code true} if this module exports or opens a package to
* the given module via its module declaration.
*/
! boolean isStaticallyExportedOrOpen(String pn, Module other, boolean open) {
// package is open to everyone or <other>
Map<String, Set<Module>> openPackages = this.openPackages;
if (openPackages != null) {
Set<Module> targets = openPackages.get(pn);
if (targets != null) {
*** 641,650 ****
--- 641,656 ----
*
* <p> This method has no effect if the package is already exported (or
* <em>open</em>) to the given module. It also has no effect if
* invoked on an {@link ModuleDescriptor#isOpen open} module. </p>
*
+ * @apiNote As specified in section 5.4.3 of the <cite>The Java™
+ * Virtual Machine Specification </cite>, if an attempt to resolve a
+ * symbolic reference fails because of a linkage error, then subsequent
+ * attempts to resolve the reference always fail with the same error that
+ * was thrown as a result of the initial resolution attempt.
+ *
* @param pn
* The package name
* @param other
* The module
*
*** 654,663 ****
--- 660,670 ----
* If {@code pn} is {@code null}, or this is a named module and the
* package {@code pn} is not a package in this module
* @throws IllegalStateException
* If this is a named module and the caller is not this module
*
+ * @jvms 5.4.3 Resolution
* @see #isExported(String,Module)
*/
@CallerSensitive
public Module addExports(String pn, Module other) {
if (pn == null)
*** 674,685 ****
return this;
}
/**
! * If the caller's module is this module then update this module to
! * <em>open</em> the given package to the given module.
* Opening a package with this method allows all types in the package,
* and all their members, not just public types and their public members,
* to be reflected on by the given module when using APIs that support
* private access or a way to bypass or suppress default Java language
* access control checks.
--- 681,692 ----
return this;
}
/**
! * If this module has <em>opened</em> a package to at least the caller
! * module then update this module to open the package to the given module.
* Opening a package with this method allows all types in the package,
* and all their members, not just public types and their public members,
* to be reflected on by the given module when using APIs that support
* private access or a way to bypass or suppress default Java language
* access control checks.
*** 697,707 ****
*
* @throws IllegalArgumentException
* If {@code pn} is {@code null}, or this is a named module and the
* package {@code pn} is not a package in this module
* @throws IllegalStateException
! * If this is a named module and the caller is not this module
*
* @see #isOpen(String,Module)
* @see AccessibleObject#setAccessible(boolean)
* @see java.lang.invoke.MethodHandles#privateLookupIn
*/
--- 704,715 ----
*
* @throws IllegalArgumentException
* If {@code pn} is {@code null}, or this is a named module and the
* package {@code pn} is not a package in this module
* @throws IllegalStateException
! * If this is a named module and this module has not opened the
! * package to at least the caller
*
* @see #isOpen(String,Module)
* @see AccessibleObject#setAccessible(boolean)
* @see java.lang.invoke.MethodHandles#privateLookupIn
*/
*** 711,723 ****
throw new IllegalArgumentException("package is null");
Objects.requireNonNull(other);
if (isNamed() && !descriptor.isOpen()) {
Module caller = Reflection.getCallerClass().getModule();
! if (caller != this) {
! throw new IllegalStateException(caller + " != " + this);
! }
implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true);
}
return this;
}
--- 719,730 ----
throw new IllegalArgumentException("package is null");
Objects.requireNonNull(other);
if (isNamed() && !descriptor.isOpen()) {
Module caller = Reflection.getCallerClass().getModule();
! if (caller != this && !isOpen(pn, caller))
! throw new IllegalStateException(pn + " is not open to " + caller);
implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true);
}
return this;
}
*** 1566,1573 ****
--- 1573,1584 ----
}
@Override
public Stream<Layer> layers(ClassLoader loader) {
return Layer.layers(loader);
}
+ @Override
+ public boolean isStaticallyExported(Module module, String pn, Module other) {
+ return module.isStaticallyExportedOrOpen(pn, other, false);
+ }
});
}
}
< prev index next >