JDK-8281006 : Module::getResourceAsStream should check if the resource is open unconditionally when caller is null
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang.module
  • Affected Version: 9
  • Priority: P4
  • Status: In Progress
  • Resolution: Unresolved
  • Submitted: 2022-01-31
  • Updated: 2022-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
Need a test to verify if Module::getResourceAsStream handles properly with null caller.   Same verification is needed for Class::getResourceAsStream.

        if (isNamed() && Resources.canEncapsulate(name)) {
            Module caller = getCallerModule(Reflection.getCallerClass());
            if (caller != this && caller != Object.class.getModule()) {
                String pn = Resources.toPackageName(name);
                if (getPackages().contains(pn)) {
                    if (caller == null && !isOpen(pn)) {
                        // no caller, package not open
                        return null;
                    }
                    if (!isOpen(pn, caller)) {
                        // package not open to caller
                        return null;
                    }
                }
            }
        }
Comments
Re-reading the code again, the implementation looks right. We should write a test to verify this.
01-02-2022

The current implementation only partly handles the "no caller frame" scenario. If the resource is in a named module and in a "package" that is open to another module (or opened unconditionally) then NPE will be thrown.
01-02-2022