On Mon, 11 Apr 2022 00:48:34 GMT, Tim Prinzing <d...@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:
>   requested changes

Marked as reviewed by mchung (Reviewer).

line 95:

> 93:     jclass class_OpenResources = (*env)->FindClass(env, 
> "open/OpenResources");
> 94:     assert(class_OpenResources != NULL);
> 95:     jmethodID mid_OpenResources_fetchClass = 
> (*env)->GetStaticMethodID(env, class_OpenResources, "fetchClass", 
> "()Ljava/lang/Class;" );

It seems that invoking `fetchClass` isn't necessary since you can simply use 
`class_OpenResources`.  Similarly for `class_ClosedResources`

line 183:

> 181:         exit(-1);
> 182:     }
> 183:     assert(in == NULL);

assert is typically used for sanity test.   As part of the test validation, 
e.g. in this case `in == NULL` or `in != NULL` in line 157,  it may be clearer 
if it's an explicit check and throw exception to indicate test failure 
especially in case `#undef NDEBUG` may not be set in the test.


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

Reply via email to