diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 6d663552433..1edac7e57db 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -76,6 +76,9 @@ Bug Fixes wrong default AttributeFactory for new Tokenizers. (Terry Smith, Uwe Schindler) +* LUCENE-7389: Fix FieldType.setDimensions(...) validation for the dimensionNumBytes + parameter. (Martijn van Groningen) + Improvements * LUCENE-7323: Compound file writing now verifies the incoming diff --git a/lucene/core/src/java/org/apache/lucene/document/FieldType.java b/lucene/core/src/java/org/apache/lucene/document/FieldType.java index 2c0a62cbce3..e0f058f520e 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FieldType.java +++ b/lucene/core/src/java/org/apache/lucene/document/FieldType.java @@ -374,7 +374,7 @@ public class FieldType implements IndexableFieldType { if (dimensionNumBytes < 0) { throw new IllegalArgumentException("dimensionNumBytes must be >= 0; got " + dimensionNumBytes); } - if (dimensionCount > PointValues.MAX_NUM_BYTES) { + if (dimensionNumBytes > PointValues.MAX_NUM_BYTES) { throw new IllegalArgumentException("dimensionNumBytes must be <= " + PointValues.MAX_NUM_BYTES + "; got " + dimensionNumBytes); } if (dimensionCount == 0) { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java index 9693c5c32b1..a846c276fef 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java @@ -362,9 +362,8 @@ public class TestPointValues extends LuceneTestCase { IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); IndexWriter w = new IndexWriter(dir, iwc); Document doc = new Document(); - doc.add(new BinaryPoint("dim", new byte[PointValues.MAX_NUM_BYTES+1])); expectThrows(IllegalArgumentException.class, () -> { - w.addDocument(doc); + doc.add(new BinaryPoint("dim", new byte[PointValues.MAX_NUM_BYTES+1])); }); Document doc2 = new Document();