diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index e222d4ef55b1..019d8adfc9cf 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -120,6 +120,9 @@ Bug Fixes * GITHUB#14682 : Fix for add char and token filters in Luke Analysis tab. (Amir Raza) +* GITHUB#14161: PointInSetQuery's constructor now throws IllegalArgumentException + instead of UnsupportedOperationException when values are out of order. (Shubham Sharma) + Build --------------------- * Upgrade forbiddenapis to version 3.9. (Uwe Schindler) diff --git a/lucene/core/src/java/org/apache/lucene/util/BytesRefBuilder.java b/lucene/core/src/java/org/apache/lucene/util/BytesRefBuilder.java index 27fc4337d256..2dff2388634b 100644 --- a/lucene/core/src/java/org/apache/lucene/util/BytesRefBuilder.java +++ b/lucene/core/src/java/org/apache/lucene/util/BytesRefBuilder.java @@ -171,4 +171,9 @@ public boolean equals(Object obj) { public int hashCode() { throw new UnsupportedOperationException(); } + + @Override + public String toString() { + return this.get().toString(); + } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java index 60906f919ee4..24fed1275f8a 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java @@ -2599,4 +2599,33 @@ public void testPointInSetQuerySkipsNonMatchingSegments() throws IOException { w.close(); dir.close(); } + + public void testOutOfOrderValuesInPointInSetQuery() throws Exception { + IllegalArgumentException expected = + expectThrows( + IllegalArgumentException.class, + () -> { + new PointInSetQuery( + "foo", + 1, + 1, + new PointInSetQuery.Stream() { + private final BytesRef[] values = { + newBytesRef(new byte[] {2}), newBytesRef(new byte[] {1}) // out of order + }; + int index = 0; + + @Override + public BytesRef next() { + return index < values.length ? values[index++] : null; + } + }) { + @Override + protected String toString(byte[] point) { + return Arrays.toString(point); + } + }; + }); + assertEquals("values are out of order: saw [2] before [1]", expected.getMessage()); + } }