Apache Lucene open-source search software
Reject binary doc-values update on an index sort field (#16565)
Jim Ferenczi850c45b264c7
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex f3b94f0e4e5..3ce8e12813c 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -223,6 +223,9 @@ Bug Fixesmerge-reuse generations, preventing progressive recall loss under low deleterates. (Ethan Baker)+* GITHUB#16565: IndexWriter#updateBinaryDocValue now rejects updating a field that is part of the+ index sort, matching IndexWriter#updateNumericDocValue. (Jim Ferenczi)+* GITHUB#14049: Randomize KNN codec params in RandomCodec. Fixes scalar quantization div-by-zerowhen all values are identical. (Mike Sokolov)diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex c4b5dc450af..67a4e7abd7a 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -1998,6 +1998,15 @@ public class IndexWriterif (value == null) {throw new IllegalArgumentException("cannot update a field to a null value: " + field);}+ // Checked before the doc-values-type check below: an index sort field is never binary, so this+ // would otherwise surface as a less clear doc-values-type mismatch.+ if (config.getIndexSortFields().contains(field)) {+ throw new IllegalArgumentException(+ "cannot update docvalues field involved in the index sort, field="+ + field+ + ", sort="+ + config.getIndexSort());+ }globalFieldNumberMap.verifyOrCreateDvOnlyField(field, DocValuesType.BINARY, true);try {return maybeProcessEvents(diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.javaindex 123d211f6db..a1a1396a3dd 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java@@ -2010,6 +2010,13 @@ public class TestIndexSorting extends LuceneTestCase {assertEquals(exc.getMessage(),"cannot update docvalues field involved in the index sort, field=foo, sort=<long: \"foo\">");+ exc =+ expectThrows(+ IllegalArgumentException.class,+ () -> w.updateBinaryDocValue(new Term("id", "0"), "foo", newBytesRef("bar")));+ assertEquals(+ exc.getMessage(),+ "cannot update docvalues field involved in the index sort, field=foo, sort=<long: \"foo\">");w.close();dir.close();}