This is an automated email from the ASF dual-hosted git repository.

krickert pushed a commit to branch OPENNLP-1851_fix_eval_failure
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/OPENNLP-1851_fix_eval_failure 
by this push:
     new d3e65a5be OPENNLP-1851: Fix 
DocumentCategorizerDLEval.categorizeFailsLoudlyOnFailure
d3e65a5be is described below

commit d3e65a5bea71d6da0947b373fa933af909208f84
Author: Kristian Rickert <[email protected]>
AuthorDate: Sat Jun 20 07:58:56 2026 -0400

    OPENNLP-1851: Fix DocumentCategorizerDLEval.categorizeFailsLoudlyOnFailure
    
    Align eval test with OPENNLP-1845 input validation and guard 
AbstractDL.close()
    when session is null.
---
 .../opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java  |  2 +-
 .../opennlp/dl/doccat/DocumentCategorizerDLEval.java     | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git 
a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java 
b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
index 6e6e54767..fe7cc99d5 100644
--- 
a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
+++ 
b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
@@ -424,7 +424,7 @@ public abstract class AbstractDL implements AutoCloseable {
    */
   @Override
   public void close() throws OrtException {
-    if (closed.compareAndSet(false, true)) {
+    if (closed.compareAndSet(false, true) && session != null) {
       session.close();
     }
   }
diff --git 
a/opennlp-eval-tests/src/test/java/opennlp/dl/doccat/DocumentCategorizerDLEval.java
 
b/opennlp-eval-tests/src/test/java/opennlp/dl/doccat/DocumentCategorizerDLEval.java
index 120e331c4..bf7002a06 100644
--- 
a/opennlp-eval-tests/src/test/java/opennlp/dl/doccat/DocumentCategorizerDLEval.java
+++ 
b/opennlp-eval-tests/src/test/java/opennlp/dl/doccat/DocumentCategorizerDLEval.java
@@ -161,17 +161,23 @@ public class DocumentCategorizerDLEval extends 
AbstractEvalTest {
     try (final DocumentCategorizerDL documentCategorizerDL =
              categorizerWithoutSession()) {
 
-      // Empty input drives categorize() down its failure path (strings[0] 
throws) before any
-      // inference; it must fail loudly rather than return an invalid all-zero 
distribution.
-      final IllegalStateException e = 
Assertions.assertThrows(IllegalStateException.class, () ->
+      // Malformed input is rejected up front with IllegalArgumentException.
+      Assertions.assertThrows(IllegalArgumentException.class, () ->
+          documentCategorizerDL.categorize(null));
+      Assertions.assertThrows(IllegalArgumentException.class, () ->
           documentCategorizerDL.categorize(new String[0]));
+
+      // Valid input with no session must fail loudly rather than return an 
invalid all-zero
+      // distribution.
+      final IllegalStateException e = 
Assertions.assertThrows(IllegalStateException.class, () ->
+          documentCategorizerDL.categorize(new String[] {"hello world"}));
       Assertions.assertTrue(e.getMessage().contains("document classification 
inference"));
 
       // The dependent API must not mask that inference failure with all-zero 
scores.
       Assertions.assertThrows(IllegalStateException.class, () ->
-          documentCategorizerDL.scoreMap(new String[0]));
+          documentCategorizerDL.scoreMap(new String[] {"hello world"}));
       Assertions.assertThrows(IllegalStateException.class, () ->
-          documentCategorizerDL.sortedScoreMap(new String[0]));
+          documentCategorizerDL.sortedScoreMap(new String[] {"hello world"}));
     }
 
   }

Reply via email to