[JEXL-446] Accept module packages with qualified exports #374
+20
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ClassTool.isExported(Class)attempts to check, on Java 9+, whether the packagecontaining the class is exported per the Java Module System. A package must at
least be exported in order for its
publicmembers to be read via reflection byanother module. It uses reflection to access the Java 9+ APIs so that JEXL can
still run on Java 8, and the check is bypassed in this case.
The issue was the use of
Module.isExported(String), which accepts only a packagename. This method is defined to return
trueif and only if the named package isunconditionally exported, i.e. to any module that wants to read it. But Java also
supports qualified exports, where a module can export a package only to one
or more specifically named other modules; this is a mechanism for least-privilege
access. For example:
JEXL 3.5.0 would accept classes from the
o.e.m.apipackage in the above example, butreject classes in
o.e.m.scriptingeven though Java would permit access to the JEXL module.The fix is to use a different overload:
Module.isExported(String, Module)passing JEXL'sown module as the 2nd method parameter. This continues to return
truefor the unqualifiedor unconditional exports, but now also returns
truefor the qualified form as well.Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.