Skip to content

Apache Lucene open-source search software

Added toString() method to BytesRefBuilder (#14676)

Shubham Sharmaa5ab7e27a279
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index e222d4ef55b..019d8adfc9c 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 27fc4337d25..2dff2388634 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 class BytesRefBuilder {
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 60906f919ee..24fed1275f8 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 class TestPointQueries extends LuceneTestCase {
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());
+ }
}