[
https://issues.apache.org/jira/browse/CODEC-324?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17908542#comment-17908542
]
Michael Froh commented on CODEC-324:
------------------------------------
Aha -- I found the following StackOverflow message:
https://stackoverflow.com/questions/45166757/loading-classes-and-resources-post-java-9,
where there was hint from the top answer:
bq. A final important difference is that non-class-file resources in a module
are encapsulated by default, and hence cannot be located from outside the
module unless their effective package is open. To load resources from your own
module it’s best to use the resource-lookup methods in Class or Module, which
can locate any resource in your module, rather than those in ClassLoader, which
can only locate non-class-file resources in the open packages of a module.
So, I decided to give that a shot -- letting the Resources class load the
resources rather than asking its classloader to do it.
With this PR: https://github.com/apache/commons-codec/pull/353, the
commons-codec-test project I created above is able to run just fine.
> BeiderMorse engine doesn't work with JPMS enabled
> -------------------------------------------------
>
> Key: CODEC-324
> URL: https://issues.apache.org/jira/browse/CODEC-324
> Project: Commons Codec
> Issue Type: Bug
> Affects Versions: 1.16.1, 1.17.0, 1.17.1
> Environment: Corretto JDK21
> JPMS enabled
> Reporter: Michael Froh
> Priority: Major
>
> With the upgrade of commons-parent from 58 to 66 in the 1.16.1 release,
> commons-codec started using Moditect to generate a modules-info.class file as
> part of the jar (which I think was added in commons-parent 59).
> A decompiled version of the modules-info looks like:
> {code:java}
> module org.apache.commons.codec {
> exports org.apache.commons.codec;
> exports org.apache.commons.codec.binary;
> exports org.apache.commons.codec.cli;
> exports org.apache.commons.codec.digest;
> exports org.apache.commons.codec.language;
> exports org.apache.commons.codec.language.bm;
> exports org.apache.commons.codec.net;
> }
> {code}
> Unfortunately, the Lang class uses reflection to load language rules.
> Eventually, it gets to the isOpen check in BuiltinClassLoader (called from
> BuiltInClassLoader's findResource), which finds that the commons-codec module
> is not open and the org.apache.commons.codec.language.bm package is not open.
> As a result, attempting to load any of the language rule files returns
> `null`, and the Resources class throws an IllegalArgumentException.
> You can see a stack trace of one such failure when trying to upgrade Lucene
> to commons-codec 1.16.1: https://github.com/apache/lucene/pull/13269
> I think there might need to be a way to pass a hint to commons-parent's pom
> to specify "opensResources" configuration for Moditect to allow the language
> rules to be loaded.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)