When TestNG invokes Class.getResourceAsStream() on an external module, it is returning null.
Per Resources visibility with java9 modules when a user wants to access /resources/someResource.xml in a library that contains module-info.java, the module must opens resources unconditionally.
Fair enough. But what happens if a user wants to access /META-INF/resources/someResource.xml in such a library? What opens instruction is necessary in this case?
UPDATE:
The bug report was filed against version 7.5 of TestNG. I just noticed that if we look at the source code of that version we see it is trying to load /META-INF/resources/webjars/jquery/3.5.1/jquery.min.js.
From my testing, opening the package is only necessary when the file is in the same package as a class in the module. In that case, you need to open the package of the class in the same module.
So, assume you have a project like the following:
and
A/module-info.java:as well as
B/module-info.java:then compile it with the following commands:
The content of class
Ais irrelevant here (it just needs to exist and have a class/interface/enum/record/whatever declaration with the correct name).We then let
Bread the filea/x/Xfrom moduleA:When running it with
it displays the first line of
a/x/X.However, we cannot access files in the same directory as the
A.classfile:If we now add
opens ainA/module-info.java(and recompile the module with the above command), the resource can be read.If we want to read
/META-INF/a/A.txtor similar (in theAmodule), noopensstatement is required as there is no class in the same package.