You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2023/10/29 15:53:44 UTC

(lucene) branch branch_9x updated: fix TestAutomaton.testRandomFinite test bug that was trying to StringsToAutomaton.build a Collection of BytesRefs containing a too-massive (> 1000 UTF-8 bytes) term; corrected the exception message to make it clear the limit is in UTF-8 bytes, not java (UTF-16) characters

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

mikemccand pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new d0eeed86e98 fix TestAutomaton.testRandomFinite test bug that was trying to StringsToAutomaton.build a Collection of BytesRefs containing a too-massive (> 1000 UTF-8 bytes) term; corrected the exception message to make it clear the limit is in UTF-8 bytes, not java (UTF-16) characters
d0eeed86e98 is described below

commit d0eeed86e989c72e57ec8e65690f98beb7e8d419
Author: Mike McCandless <mi...@apache.org>
AuthorDate: Sun Oct 29 11:41:40 2023 -0400

    fix TestAutomaton.testRandomFinite test bug that was trying to StringsToAutomaton.build a Collection of BytesRefs containing a too-massive (> 1000 UTF-8 bytes) term; corrected the exception message to make it clear the limit is in UTF-8 bytes, not java (UTF-16) characters
---
 .../lucene/util/automaton/DaciukMihovAutomatonBuilder.java    |  2 +-
 .../test/org/apache/lucene/util/automaton/TestAutomaton.java  | 11 ++++++++++-
 .../util/automaton/TestDaciukMihovAutomatonBuilder.java       |  2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/DaciukMihovAutomatonBuilder.java b/lucene/core/src/java/org/apache/lucene/util/automaton/DaciukMihovAutomatonBuilder.java
index 7048d4538d1..df12250f4ef 100644
--- a/lucene/core/src/java/org/apache/lucene/util/automaton/DaciukMihovAutomatonBuilder.java
+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/DaciukMihovAutomatonBuilder.java
@@ -286,7 +286,7 @@ public final class DaciukMihovAutomatonBuilder {
       throw new IllegalArgumentException(
           "This builder doesn't allow terms that are larger than "
               + Automata.MAX_STRING_UNION_TERM_LENGTH
-              + " characters, got "
+              + " UTF-8 bytes, got "
               + current);
     }
     assert stateRegistry != null : "Automaton already built.";
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
index 093882a3001..a3eba611df9 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
@@ -790,9 +790,18 @@ public class TestAutomaton extends LuceneTestCase {
     return null;
   }
 
+  private static boolean hasMassiveTerm(Collection<BytesRef> terms) {
+    for (BytesRef term : terms) {
+      if (term.length > Automata.MAX_STRING_UNION_TERM_LENGTH) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   private Automaton unionTerms(Collection<BytesRef> terms) {
     Automaton a;
-    if (random().nextBoolean()) {
+    if (random().nextBoolean() || hasMassiveTerm(terms)) {
       if (VERBOSE) {
         System.out.println("TEST: unionTerms: use union");
       }
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestDaciukMihovAutomatonBuilder.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestDaciukMihovAutomatonBuilder.java
index d72e08f18e9..835c4d0be9d 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestDaciukMihovAutomatonBuilder.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestDaciukMihovAutomatonBuilder.java
@@ -105,7 +105,7 @@ public class TestDaciukMihovAutomatonBuilder extends LuceneTestCase {
             .startsWith(
                 "This builder doesn't allow terms that are larger than "
                     + Automata.MAX_STRING_UNION_TERM_LENGTH
-                    + " characters"));
+                    + " UTF-8 bytes"));
 
     byte[] b1k = ArrayUtil.copyOfSubArray(b10k, 0, 1000);
     build(Collections.singleton(new BytesRef(b1k)), false); // no exception