mirror of https://github.com/apache/lucene.git
LUCENE-7027: Fixed NumericTermAttribute to not throw IllegalArgumentException after NumericTokenStream was exhausted
This commit is contained in:
parent
779120c6a4
commit
42ae21cb9a
|
@ -241,6 +241,10 @@ Bug Fixes
|
||||||
* LUCENE-7002: Fixed MultiCollector to not throw a NPE if setScorer is called
|
* LUCENE-7002: Fixed MultiCollector to not throw a NPE if setScorer is called
|
||||||
after one of the sub collectors is done collecting. (John Wang, Adrien Grand)
|
after one of the sub collectors is done collecting. (John Wang, Adrien Grand)
|
||||||
|
|
||||||
|
* LUCENE-7027: Fixed NumericTermAttribute to not throw IllegalArgumentException
|
||||||
|
after NumericTokenStream was exhausted. (Uwe Schindler, Lee Hinman,
|
||||||
|
Mike McCandless)
|
||||||
|
|
||||||
Other
|
Other
|
||||||
|
|
||||||
* LUCENE-6924: Upgrade randomizedtesting to 2.3.2. (Dawid Weiss)
|
* LUCENE-6924: Upgrade randomizedtesting to 2.3.2. (Dawid Weiss)
|
||||||
|
|
|
@ -157,7 +157,9 @@ public final class LegacyNumericTokenStream extends TokenStream {
|
||||||
@Override
|
@Override
|
||||||
public BytesRef getBytesRef() {
|
public BytesRef getBytesRef() {
|
||||||
assert valueSize == 64 || valueSize == 32;
|
assert valueSize == 64 || valueSize == 32;
|
||||||
if (valueSize == 64) {
|
if (shift >= valueSize) {
|
||||||
|
bytes.clear();
|
||||||
|
} else if (valueSize == 64) {
|
||||||
LegacyNumericUtils.longToPrefixCoded(value, shift, bytes);
|
LegacyNumericUtils.longToPrefixCoded(value, shift, bytes);
|
||||||
} else {
|
} else {
|
||||||
LegacyNumericUtils.intToPrefixCoded((int) value, shift, bytes);
|
LegacyNumericUtils.intToPrefixCoded((int) value, shift, bytes);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.lucene.analysis;
|
package org.apache.lucene.analysis;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.LegacyNumericUtils;
|
import org.apache.lucene.util.LegacyNumericUtils;
|
||||||
import org.apache.lucene.analysis.LegacyNumericTokenStream.LegacyNumericTermAttributeImpl;
|
import org.apache.lucene.analysis.LegacyNumericTokenStream.LegacyNumericTermAttributeImpl;
|
||||||
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
|
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
|
||||||
|
@ -25,10 +26,11 @@ import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
|
||||||
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
||||||
import org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl;
|
import org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class TestNumericTokenStream extends BaseTokenStreamTestCase {
|
public class TestNumericTokenStream extends BaseTokenStreamTestCase {
|
||||||
|
|
||||||
static final long lvalue = 4573245871874382L;
|
final long lvalue = random().nextLong();
|
||||||
static final int ivalue = 123456;
|
final int ivalue = random().nextInt();
|
||||||
|
|
||||||
public void testLongStream() throws Exception {
|
public void testLongStream() throws Exception {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
|
@ -116,13 +118,61 @@ public class TestNumericTokenStream extends BaseTokenStreamTestCase {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** LUCENE-7027 */
|
||||||
|
public void testCaptureStateAfterExhausted() throws Exception {
|
||||||
|
// default precstep
|
||||||
|
try (LegacyNumericTokenStream stream=new LegacyNumericTokenStream()) {
|
||||||
|
// int
|
||||||
|
stream.setIntValue(ivalue);
|
||||||
|
stream.reset();
|
||||||
|
while (stream.incrementToken());
|
||||||
|
stream.captureState();
|
||||||
|
stream.end();
|
||||||
|
stream.captureState();
|
||||||
|
// long
|
||||||
|
stream.setLongValue(lvalue);
|
||||||
|
stream.reset();
|
||||||
|
while (stream.incrementToken());
|
||||||
|
stream.captureState();
|
||||||
|
stream.end();
|
||||||
|
stream.captureState();
|
||||||
|
}
|
||||||
|
// huge precstep
|
||||||
|
try (LegacyNumericTokenStream stream=new LegacyNumericTokenStream(Integer.MAX_VALUE)) {
|
||||||
|
// int
|
||||||
|
stream.setIntValue(ivalue);
|
||||||
|
stream.reset();
|
||||||
|
while (stream.incrementToken());
|
||||||
|
stream.captureState();
|
||||||
|
stream.end();
|
||||||
|
stream.captureState();
|
||||||
|
// long
|
||||||
|
stream.setLongValue(lvalue);
|
||||||
|
stream.reset();
|
||||||
|
while (stream.incrementToken());
|
||||||
|
stream.captureState();
|
||||||
|
stream.end();
|
||||||
|
stream.captureState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testAttributeClone() throws Exception {
|
public void testAttributeClone() throws Exception {
|
||||||
LegacyNumericTermAttributeImpl att = new LegacyNumericTermAttributeImpl();
|
LegacyNumericTermAttributeImpl att = new LegacyNumericTermAttributeImpl();
|
||||||
att.init(1234L, 64, 8, 0); // set some value, to make getBytesRef() work
|
att.init(lvalue, 64, 8, 0); // set some value, to make getBytesRef() work
|
||||||
LegacyNumericTermAttributeImpl copy = TestCharTermAttributeImpl.assertCloneIsEqual(att);
|
LegacyNumericTermAttributeImpl copy = TestCharTermAttributeImpl.assertCloneIsEqual(att);
|
||||||
assertNotSame(att.getBytesRef(), copy.getBytesRef());
|
assertNotSame(att.getBytesRef(), copy.getBytesRef());
|
||||||
LegacyNumericTermAttributeImpl copy2 = TestCharTermAttributeImpl.assertCopyIsEqual(att);
|
LegacyNumericTermAttributeImpl copy2 = TestCharTermAttributeImpl.assertCopyIsEqual(att);
|
||||||
assertNotSame(att.getBytesRef(), copy2.getBytesRef());
|
assertNotSame(att.getBytesRef(), copy2.getBytesRef());
|
||||||
|
|
||||||
|
// LUCENE-7027 test
|
||||||
|
att.init(lvalue, 64, 8, 64); // Exhausted TokenStream -> should return empty BytesRef
|
||||||
|
assertEquals(new BytesRef(), att.getBytesRef());
|
||||||
|
copy = TestCharTermAttributeImpl.assertCloneIsEqual(att);
|
||||||
|
assertEquals(new BytesRef(), copy.getBytesRef());
|
||||||
|
assertNotSame(att.getBytesRef(), copy.getBytesRef());
|
||||||
|
copy2 = TestCharTermAttributeImpl.assertCopyIsEqual(att);
|
||||||
|
assertEquals(new BytesRef(), copy2.getBytesRef());
|
||||||
|
assertNotSame(att.getBytesRef(), copy2.getBytesRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue