Richard Zowalla created OPENNLP-1959:
----------------------------------------

             Summary: BaseModel fails to load on Android: 
java.io.ObjectInputFilter is not available
                 Key: OPENNLP-1959
                 URL: https://issues.apache.org/jira/browse/OPENNLP-1959
             Project: OpenNLP
          Issue Type: Bug
    Affects Versions: 3.0.0-M6, 3.0.0-M5, 2.5.11, 2.5.12
            Reporter: Richard Zowalla
             Fix For: 3.0.0, 2.5.13


OPENNLP\-1891 added a static field to {{opennlp.tools.util.model.BaseModel}}:

{code}
private static final ObjectInputFilter DESERIALIZE_FILTER = 
ObjectInputFilter.Config.createFilter(...);
{code}

{{java.io.ObjectInputFilter}} is not part of the Android SDK, including API 36. 
This breaks Android users such as GrapheneOS SpeechServices, who already hit 
OPENNLP\-1785 and OPENNLP\-1835 in the XML parser setup.

_Build time:_ R8 8.13.23 against {{android.jar}} \(API 36\), using 
SpeechServices' keep rules:
\- opennlp\-tools 2.5.10: passes
\- opennlp\-tools 2.5.11: fails with {{Missing class 
java.io.ObjectInputFilter}} and {{java.io.ObjectInputFilter$Config}}

_Runtime:_ {{\-dontwarn}} does not help. The static initializer of 
{{BaseModel}} is expected to throw {{NoClassDefFoundError}} on ART, so every 
model load \({{TokenizerModel}}, {{POSModel}}, ...\) fails. This has been 
checked with R8 only, not yet on a device.

_Proposed fix:_ create the filter lazily, for example in a holder class, and 
only when the platform provides {{java.io.ObjectInputFilter}}, so {{BaseModel}} 
loads on Android. {{SvmDoccatModel}} in opennlp\-ml\-libsvm uses 
{{ObjectInputFilter}} too, but only inside a method.

_Related \(3.0.0, OPENNLP\-1957 / PR #1306\):_ Apache Commons Secure XML 
references {{net.sf.saxon.\*}} directly and ships no R8 consumer rules. With 
minification enabled, R8 fails with 8 missing\-class errors unless {{\-dontwarn 
net.sf.saxon.\*\*}} is added. That code is never reached at runtime. Consider 
shipping that rule in {{META\-INF/proguard/}}, here or upstream.

Downstream report: 
[https://github.com/GrapheneOS/SpeechServices/issues/32|https://github.com/GrapheneOS/SpeechServices/issues/32]





--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to