From f3c50f966a4a441f34fd518a669f9398c2d4ab0a Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Mon, 7 Oct 2019 11:45:53 +0200 Subject: [PATCH] Fix test bug in TestFeatureSort.testDuelFloat. It could index out-of-range frequencies. --- .../core/src/java/org/apache/lucene/document/FeatureField.java | 2 +- .../src/test/org/apache/lucene/document/TestFeatureSort.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/document/FeatureField.java b/lucene/core/src/java/org/apache/lucene/document/FeatureField.java index 229e0571ed3..2ca048c5270 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FeatureField.java +++ b/lucene/core/src/java/org/apache/lucene/document/FeatureField.java @@ -197,7 +197,7 @@ public final class FeatureField extends Field { } } - private static final int MAX_FREQ = Float.floatToIntBits(Float.MAX_VALUE) >>> 15; + static final int MAX_FREQ = Float.floatToIntBits(Float.MAX_VALUE) >>> 15; static float decodeFeatureValue(float freq) { if (freq > MAX_FREQ) { diff --git a/lucene/core/src/test/org/apache/lucene/document/TestFeatureSort.java b/lucene/core/src/test/org/apache/lucene/document/TestFeatureSort.java index 3c8fef11728..1090e5a5679 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestFeatureSort.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestFeatureSort.java @@ -230,7 +230,7 @@ public class TestFeatureSort extends LuceneTestCase { if (random().nextBoolean()) { float f; do { - int freq = TestUtil.nextInt(random(), 1, (1 << 16) - 1); + int freq = TestUtil.nextInt(random(), 1, FeatureField.MAX_FREQ); f = FeatureField.decodeFeatureValue(freq); } while (f < Float.MIN_NORMAL); doc.add(new NumericDocValuesField("float", Float.floatToIntBits(f)));