You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2026/02/22 12:53:20 UTC

(lucene) branch main updated: Remove deprecated RegExp complement syntax (#15750)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new b18af560da6 Remove deprecated RegExp complement syntax (#15750)
b18af560da6 is described below

commit b18af560da6e954cde6b9e673ee5d2dd0e32cb6a
Author: Saurabh Singh <si...@amazon.com>
AuthorDate: Sun Feb 22 04:53:14 2026 -0800

    Remove deprecated RegExp complement syntax (#15750)
    
    - Remove DEPRECATED_COMPLEMENT flag (deprecated in Lucene 10)
    - Remove REGEXP_DEPRECATED_COMPLEMENT enum value
    - Remove makeDeprecatedComplement() method
    - Remove deprecated test testDeprecatedComplement()
    - Update MIGRATE.md to reflect removal
    - Users should migrate to complement bracket expressions ([^...])
    
    Fixes deprecation marked for removal in Lucene 11
---
 lucene/CHANGES.txt                                 |  4 ++
 lucene/MIGRATE.md                                  | 20 ++++------
 .../org/apache/lucene/util/automaton/RegExp.java   | 46 ++--------------------
 .../apache/lucene/util/automaton/TestRegExp.java   | 16 --------
 4 files changed, 15 insertions(+), 71 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index aa54a8dd4cd..7d140997d55 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -7,6 +7,10 @@ http://s.apache.org/luceneversions
 
 API Changes
 ---------------------
+* GITHUB#XXXXX: Remove deprecated RegExp complement syntax support. The DEPRECATED_COMPLEMENT flag,
+  REGEXP_DEPRECATED_COMPLEMENT enum value, and makeDeprecatedComplement method have been removed.
+  Users should use complement bracket expressions ([^...]) instead. (Saurabh Singh)
+
 * GITHUB#15517: Remove newHashMap, newHashSet from CollectionUtil, and use HashMap.newHashMap, HashSet.newHashSet
   directly. (Zhou Hui)
 
diff --git a/lucene/MIGRATE.md b/lucene/MIGRATE.md
index 14b799c4184..95b652fde9f 100644
--- a/lucene/MIGRATE.md
+++ b/lucene/MIGRATE.md
@@ -250,18 +250,14 @@ These classes no longer take a `determinizeWorkLimit` and no longer determinize
 behind the scenes. It is the responsibility of the caller to call
 `Operations.determinize()` for DFA execution.
 
-### RegExp optional complement syntax has been deprecated
-
-Support for the optional complement syntax (`~`) has been deprecated.
-The `COMPLEMENT` syntax flag has been removed and replaced by the
-`DEPRECATED_COMPLEMENT` flag. Users wanting to enable the deprecated
-complement support can do so by explicitly passing a syntax flags that
-has `DEPRECATED_COMPLEMENT` when creating a `RegExp`. For example:
-`new RegExp("~(foo)", RegExp.DEPRECATED_COMPLEMENT)`.
-
-Alternatively, and quite commonly, a more simple _complement bracket expression_,
-`[^...]`, may be a suitable replacement, For example, `[^fo]` matches any
-character that is not an `f` or `o`.
+### RegExp optional complement syntax has been removed (LUCENE-11)
+
+Support for the optional complement syntax (`~`) that was deprecated in Lucene 10
+has been removed. The `DEPRECATED_COMPLEMENT` flag and `REGEXP_DEPRECATED_COMPLEMENT`
+enum value are no longer available.
+
+Users should migrate to using _complement bracket expressions_ (`[^...]`) instead.
+For example, `[^fo]` matches any character that is not an `f` or `o`.
 
 ### DocValuesFieldExistsQuery, NormsFieldExistsQuery and KnnVectorFieldExistsQuery removed in favor of FieldExistsQuery (LUCENE-10436)
 
diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java b/lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java
index 10b692e89b4..0d2e78ee167 100644
--- a/lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java
+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java
@@ -389,14 +389,7 @@ public class RegExp {
     /** An Automaton expression */
     REGEXP_AUTOMATON,
     /** An Interval expression */
-    REGEXP_INTERVAL,
-    /**
-     * The complement of an expression.
-     *
-     * @deprecated Will be removed in Lucene 11
-     */
-    @Deprecated
-    REGEXP_DEPRECATED_COMPLEMENT
+    REGEXP_INTERVAL
   }
 
   // -----  Syntax flags ( <= 0xff )  ------
@@ -487,18 +480,6 @@ public class RegExp {
    */
   public static final int CASE_INSENSITIVE_RANGE = 0x0400;
 
-  // -----  Deprecated flags ( > 0xffff )  ------
-
-  /**
-   * Allows regexp parsing of the complement (<code>~</code>).
-   *
-   * <p>Note that processing the complement can require exponential time, but will be bounded by an
-   * internal limit. Regexes exceeding the limit will fail with TooComplexToDeterminizeException.
-   *
-   * @deprecated This method will be removed in Lucene 11
-   */
-  @Deprecated public static final int DEPRECATED_COMPLEMENT = 0x10000;
-
   // Immutable parsed state
   /** The type of expression */
   public final Kind kind;
@@ -553,7 +534,7 @@ public class RegExp {
    * @exception IllegalArgumentException if an error occurred while parsing the regular expression
    */
   public RegExp(String s, int syntax_flags, int match_flags) throws IllegalArgumentException {
-    if ((syntax_flags & ~DEPRECATED_COMPLEMENT) > ALL) {
+    if (syntax_flags > ALL) {
       throw new IllegalArgumentException("Illegal syntax flag");
     }
 
@@ -699,12 +680,6 @@ public class RegExp {
         a = exp1.toAutomaton(automata, automaton_provider);
         a = Operations.complement(a, Integer.MAX_VALUE);
         break;
-      case REGEXP_DEPRECATED_COMPLEMENT:
-        // to ease transitions for users only, support arbitrary complement
-        // but bounded by DEFAULT_DETERMINIZE_WORK_LIMIT: must not be configurable.
-        a = exp1.toAutomaton(automata, automaton_provider);
-        a = Operations.complement(a, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
-        break;
       case REGEXP_CHAR:
         if (check(ASCII_CASE_INSENSITIVE | CASE_INSENSITIVE)) {
           a = Automata.makeCharSet(toCaseInsensitiveChar(c));
@@ -908,7 +883,6 @@ public class RegExp {
         b.append("){").append(min).append(",").append(max).append("}");
         break;
       case REGEXP_COMPLEMENT:
-      case REGEXP_DEPRECATED_COMPLEMENT:
         b.append("~(");
         exp1.toStringBuilder(b);
         b.append(")");
@@ -985,7 +959,6 @@ public class RegExp {
       case REGEXP_OPTIONAL:
       case REGEXP_REPEAT:
       case REGEXP_COMPLEMENT:
-      case REGEXP_DEPRECATED_COMPLEMENT:
         b.append(indent);
         b.append(kind);
         b.append('\n');
@@ -1106,7 +1079,6 @@ public class RegExp {
       case REGEXP_REPEAT_MIN:
       case REGEXP_REPEAT_MINMAX:
       case REGEXP_COMPLEMENT:
-      case REGEXP_DEPRECATED_COMPLEMENT:
         exp1.getIdentifiers(set);
         break;
       case REGEXP_AUTOMATON:
@@ -1183,16 +1155,6 @@ public class RegExp {
     return newContainerNode(flags, Kind.REGEXP_COMPLEMENT, exp, null);
   }
 
-  /**
-   * Creates node that will compute complement of arbitrary expression.
-   *
-   * @deprecated Will be removed in Lucene 11
-   */
-  @Deprecated
-  static RegExp makeDeprecatedComplement(int flags, RegExp exp) {
-    return newContainerNode(flags, Kind.REGEXP_DEPRECATED_COMPLEMENT, exp, null);
-  }
-
   static RegExp makeChar(int flags, int c) {
     return newLeafNode(flags, Kind.REGEXP_CHAR, null, c, 0, 0, 0, null, null);
   }
@@ -1341,9 +1303,7 @@ public class RegExp {
   }
 
   final RegExp parseComplExp() throws IllegalArgumentException {
-    if (check(DEPRECATED_COMPLEMENT) && match('~'))
-      return makeDeprecatedComplement(flags, parseComplExp());
-    else return parseCharClassExp();
+    return parseCharClassExp();
   }
 
   final RegExp parseCharClassExp() throws IllegalArgumentException {
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
index d1348781526..f906a08ee31 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
@@ -25,7 +25,6 @@ import static org.hamcrest.Matchers.not;
 import java.util.Locale;
 import java.util.regex.Pattern;
 import org.apache.lucene.tests.util.LuceneTestCase;
-import org.apache.lucene.tests.util.automaton.AutomatonTestUtil;
 import org.apache.lucene.util.BytesRef;
 
 public class TestRegExp extends LuceneTestCase {
@@ -332,19 +331,4 @@ public class TestRegExp extends LuceneTestCase {
   public void testRegExpNoStackOverflow() {
     new RegExp("(a)|".repeat(50000) + "(a)");
   }
-
-  /**
-   * Tests the deprecate complement flag. Keep the simple test only, no random tests to let it cause
-   * us pain.
-   *
-   * @deprecated Remove in Lucene 11
-   */
-  @Deprecated
-  public void testDeprecatedComplement() {
-    Automaton expected =
-        Operations.complement(
-            Automata.makeString("abcd"), Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
-    Automaton actual = new RegExp("~(abcd)", RegExp.DEPRECATED_COMPLEMENT).toAutomaton();
-    assertTrue(AutomatonTestUtil.sameLanguage(expected, actual));
-  }
 }