RFR: JDK-8281006 Module::getResourceAsStream should check if the resource is open unconditionally when caller is null [v3]

Alan Bateman alanb at openjdk.java.net
Sun Apr 10 15:52:42 UTC 2022


On Thu, 7 Apr 2022 21:08:34 GMT, Tim Prinzing <duke at openjdk.java.net> wrote:

>> Created a test called NullCallerGetResource to test Module::getResourceAsStream and Class::getResourceAsStream from the native level.
>> 
>> At the java level the test builds a test module called 'n' which opens the package 'open' to everyone. There is also a package 'closed' which is neither opened or exported. Both packages have a text file called 'test.txt'. The open package has a class called OpenResources and the closed package has a class called ClosedResources. The native test is launched with the test module n added.
>> 
>> At the native level the test tries to read both the open and closed resource from both the classes and the module. It performs the equivalent of the following java operations:
>> 
>> Class c = open.OpenResources.fetchClass();
>> InputStream in = c.getResourceAsStream("test.txt");
>> assert(in != null); in.close();
>> 
>> Module n = c.getModule();
>> in = n.getResourceAsStream("open/test.txt");
>> assert(in != null); in.close();
>> 
>> Class closed = closed.ClosedResources.fetchClass();
>> assert(closedsStream("test.txt") == null);
>> assert(n.getResourceAsStream("closed/test.txt") == null);
>> 
>> The test initially threw an NPE when trying to fetch the open resource. The Module class was fixed by removing the fragment with the (caller == null) test in getResourceAsStream, and changing the call to isOpen(String,Module) to use EVERYONE_MODULE if the caller module is null.
>
> Tim Prinzing has updated the pull request incrementally with one additional commit since the last revision:
> 
>   revert Module::isOpen

The updated changes to Class and Module in 912896d7 look okay, just minor comments.

src/java.base/share/classes/java/lang/Class.java line 3007:

> 3005:                 if (callerModule == null) {
> 3006:                     // no caller
> 3007:                     return thisModule.isOpen(pn);

It might be clear if the comment read "no caller, return true if the package is open to all modules".

src/java.base/share/classes/java/lang/Module.java line 1658:

> 1656:                 if (getPackages().contains(pn)) {
> 1657:                     if (caller == null) {
> 1658:                         if (! isOpen(pn)) {

Minor nit, can you remove the space in "! isOpen".

-------------

PR: https://git.openjdk.java.net/jdk/pull/8134



More information about the build-dev mailing list