OPENNLP-1839: Fix native memory leak and vocabulary NPE in DocumentCategorizerDL#1074
Merged
Merged
Conversation
…ategorizerDL Every categorize() call leaked the OnnxTensor inputs and the OrtSession.Result for each document chunk. Tensors are now closed in a finally block and the result with try-with-resources. Tokens absent from the vocabulary caused an opaque NullPointerException through auto-unboxing, which the broad catch in categorize() swallowed. The token-to-id mapping now throws IllegalArgumentException naming the missing token, indicating a vocabulary/model mismatch.
This was referenced Jun 12, 2026
rzo1
approved these changes
Jun 12, 2026
Contributor
|
Might need to be back-ported to 2.x as well |
mawiesne
approved these changes
Jun 12, 2026
mawiesne
pushed a commit
that referenced
this pull request
Jun 12, 2026
…ategorizerDL (#1074) Every categorize() call leaked the OnnxTensor inputs and the OrtSession.Result for each document chunk. Tensors are now closed in a finally block and the result with try-with-resources. Tokens absent from the vocabulary caused an opaque NullPointerException through auto-unboxing, which the broad catch in categorize() swallowed. The token-to-id mapping now throws IllegalArgumentException naming the missing token, indicating a vocabulary/model mismatch. (cherry picked from commit b6af875)
Contributor
|
🍒 -picked to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
categorize()leaked native memory on every call: theOnnxTensorinputs and theOrtSession.Resultwere never closed. Tensors are now released in afinallyblock and the result via try-with-resources (getValue()copies into Java arrays first, so this is safe).vocab.get(...)to auto-unboxnullinto anint, throwing an opaqueNullPointerExceptionthat the broad catch incategorize()swallowed into an empty score array. The mapping loop is now a testabletokenIds()helper that throwsIllegalArgumentExceptionnaming the missing token, which indicates the vocabulary file does not match the model.Why
See OPENNLP-1839. Long-running services calling
categorize()repeatedly accumulate off-heap allocations until the process is killed. This applies the same resource-management pattern as theSentenceVectorsDLfix (OPENNLP-1836, #1072).Validation
New
DocumentCategorizerDLTestcovers the token-id mapping and the vocabulary-miss error. All existingopennlp-dltests pass.