Skip to content

Apache Lucene open-source search software

LUCENE-10052: cutover more tests to newBytesRef, and finally catches a fly (FSTTermsReader.IntersectEnum was illegally ignoring BytesRef.offset, yay!) (#258)

Michael McCandless88588e3deaa1
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/FSTTermsReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/FSTTermsReader.java
index 9f988257b5d..4f3791ee6e8 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/FSTTermsReader.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/FSTTermsReader.java
@@ -581,7 +581,7 @@ public class FSTTermsReader extends FieldsProducer {
int label, upto = 0, limit = target.length;
while (upto < limit) { // to target prefix, or ceil label (rewind prefix)
frame = newFrame();
- label = target.bytes[upto] & 0xff;
+ label = target.bytes[target.offset + upto] & 0xff;
frame = loadCeilFrame(label, topFrame(), frame);
if (frame == null || frame.fstArc.label() != label) {
break;
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestField.java b/lucene/core/src/test/org/apache/lucene/document/TestField.java
index 1075e416956..4f57a21ed2a 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestField.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestField.java
@@ -268,11 +268,11 @@ public class TestField extends LuceneTestCase {
}
public void testSortedBytesDocValuesField() throws Exception {
- SortedDocValuesField field = new SortedDocValuesField("foo", new BytesRef("bar"));
+ SortedDocValuesField field = new SortedDocValuesField("foo", newBytesRef("bar"));
trySetByteValue(field);
field.setBytesValue("fubar".getBytes(StandardCharsets.UTF_8));
- field.setBytesValue(new BytesRef("baz"));
+ field.setBytesValue(newBytesRef("baz"));
trySetDoubleValue(field);
trySetIntValue(field);
trySetFloatValue(field);
@@ -282,15 +282,15 @@ public class TestField extends LuceneTestCase {
trySetStringValue(field);
trySetTokenStreamValue(field);
- assertEquals(new BytesRef("baz"), field.binaryValue());
+ assertEquals(newBytesRef("baz"), field.binaryValue());
}
public void testBinaryDocValuesField() throws Exception {
- BinaryDocValuesField field = new BinaryDocValuesField("foo", new BytesRef("bar"));
+ BinaryDocValuesField field = new BinaryDocValuesField("foo", newBytesRef("bar"));
trySetByteValue(field);
field.setBytesValue("fubar".getBytes(StandardCharsets.UTF_8));
- field.setBytesValue(new BytesRef("baz"));
+ field.setBytesValue(newBytesRef("baz"));
trySetDoubleValue(field);
trySetIntValue(field);
trySetFloatValue(field);
@@ -300,7 +300,7 @@ public class TestField extends LuceneTestCase {
trySetStringValue(field);
trySetTokenStreamValue(field);
- assertEquals(new BytesRef("baz"), field.binaryValue());
+ assertEquals(newBytesRef("baz"), field.binaryValue());
}
public void testStringField() throws Exception {
@@ -379,13 +379,13 @@ public class TestField extends LuceneTestCase {
new Field[] {
new StoredField("foo", "bar".getBytes(StandardCharsets.UTF_8)),
new StoredField("foo", "bar".getBytes(StandardCharsets.UTF_8), 0, 3),
- new StoredField("foo", new BytesRef("bar")),
+ new StoredField("foo", newBytesRef("bar")),
};
for (Field field : fields) {
trySetByteValue(field);
field.setBytesValue("baz".getBytes(StandardCharsets.UTF_8));
- field.setBytesValue(new BytesRef("baz"));
+ field.setBytesValue(newBytesRef("baz"));
trySetDoubleValue(field);
trySetIntValue(field);
trySetFloatValue(field);
@@ -395,7 +395,7 @@ public class TestField extends LuceneTestCase {
trySetStringValue(field);
trySetTokenStreamValue(field);
- assertEquals(new BytesRef("baz"), field.binaryValue());
+ assertEquals(newBytesRef("baz"), field.binaryValue());
}
}
@@ -488,7 +488,7 @@ public class TestField extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- BytesRef br = new BytesRef(new byte[5]);
+ BytesRef br = newBytesRef(new byte[5]);
Field field = new StringField("binary", br, Field.Store.YES);
assertEquals(br, field.binaryValue());
doc.add(field);
@@ -526,7 +526,7 @@ public class TestField extends LuceneTestCase {
expectThrows(
IllegalArgumentException.class,
() -> {
- f.setBytesValue(new BytesRef("bogus"));
+ f.setBytesValue(newBytesRef("bogus"));
});
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCustomTermFreq.java b/lucene/core/src/test/org/apache/lucene/index/TestCustomTermFreq.java
index 790654e492d..a3429a0a138 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestCustomTermFreq.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestCustomTermFreq.java
@@ -31,7 +31,6 @@ import org.apache.lucene.search.CollectionStatistics;
import org.apache.lucene.search.TermStatistics;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
@@ -87,14 +86,14 @@ public class TestCustomTermFreq extends LuceneTestCase {
w.addDocument(doc);
IndexReader r = DirectoryReader.open(w);
PostingsEnum postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("bar"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("bar"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(128, postings.freq());
assertEquals(NO_MORE_DOCS, postings.nextDoc());
postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("foo"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("foo"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(42, postings.freq());
@@ -129,7 +128,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
IndexReader r = DirectoryReader.open(w);
PostingsEnum postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("bar"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("bar"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(128, postings.freq());
@@ -138,7 +137,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
assertEquals(NO_MORE_DOCS, postings.nextDoc());
postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("foo"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("foo"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(42, postings.freq());
@@ -166,14 +165,14 @@ public class TestCustomTermFreq extends LuceneTestCase {
w.addDocument(doc);
IndexReader r = DirectoryReader.open(w);
PostingsEnum postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("bar"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("bar"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(228, postings.freq());
assertEquals(NO_MORE_DOCS, postings.nextDoc());
postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("foo"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("foo"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(59, postings.freq());
@@ -211,7 +210,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
IndexReader r = DirectoryReader.open(w);
PostingsEnum postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("bar"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("bar"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(228, postings.freq());
@@ -220,7 +219,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
assertEquals(NO_MORE_DOCS, postings.nextDoc());
postings =
- MultiTerms.getTermPostingsEnum(r, "field", new BytesRef("foo"), (int) PostingsEnum.FREQS);
+ MultiTerms.getTermPostingsEnum(r, "field", newBytesRef("foo"), (int) PostingsEnum.FREQS);
assertNotNull(postings);
assertEquals(0, postings.nextDoc());
assertEquals(59, postings.freq());
@@ -261,9 +260,9 @@ public class TestCustomTermFreq extends LuceneTestCase {
IndexReader r = DirectoryReader.open(w);
TermsEnum termsEnum = MultiTerms.getTerms(r, "field").iterator();
- assertTrue(termsEnum.seekExact(new BytesRef("foo")));
+ assertTrue(termsEnum.seekExact(newBytesRef("foo")));
assertEquals(179, termsEnum.totalTermFreq());
- assertTrue(termsEnum.seekExact(new BytesRef("bar")));
+ assertTrue(termsEnum.seekExact(newBytesRef("bar")));
assertEquals(368, termsEnum.totalTermFreq());
IOUtils.close(r, w, dir);
@@ -441,7 +440,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
Fields fields = r.getTermVectors(0);
TermsEnum termsEnum = fields.terms("field").iterator();
- assertTrue(termsEnum.seekExact(new BytesRef("bar")));
+ assertTrue(termsEnum.seekExact(newBytesRef("bar")));
assertEquals(228, termsEnum.totalTermFreq());
PostingsEnum postings = termsEnum.postings(null);
assertNotNull(postings);
@@ -449,7 +448,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
assertEquals(228, postings.freq());
assertEquals(NO_MORE_DOCS, postings.nextDoc());
- assertTrue(termsEnum.seekExact(new BytesRef("foo")));
+ assertTrue(termsEnum.seekExact(newBytesRef("foo")));
assertEquals(59, termsEnum.totalTermFreq());
postings = termsEnum.postings(null);
assertNotNull(postings);
@@ -459,7 +458,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
fields = r.getTermVectors(1);
termsEnum = fields.terms("field").iterator();
- assertTrue(termsEnum.seekExact(new BytesRef("bar")));
+ assertTrue(termsEnum.seekExact(newBytesRef("bar")));
assertEquals(140, termsEnum.totalTermFreq());
postings = termsEnum.postings(null);
assertNotNull(postings);
@@ -467,7 +466,7 @@ public class TestCustomTermFreq extends LuceneTestCase {
assertEquals(140, postings.freq());
assertEquals(NO_MORE_DOCS, postings.nextDoc());
- assertTrue(termsEnum.seekExact(new BytesRef("foo")));
+ assertTrue(termsEnum.seekExact(newBytesRef("foo")));
assertEquals(120, termsEnum.totalTermFreq());
postings = termsEnum.postings(null);
assertNotNull(postings);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
index 5c981c4d57e..ed48a0754cf 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
@@ -122,7 +122,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
// Index doc values are single-valued so we should not
// be able to add same field more than once:
- doc.add(new BinaryDocValuesField("field", new BytesRef("blah")));
+ doc.add(new BinaryDocValuesField("field", newBytesRef("blah")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -147,7 +147,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
// Index doc values are single-valued so we should not
// be able to add same field more than once:
- doc.add(new SortedDocValuesField("field", new BytesRef("hello")));
+ doc.add(new SortedDocValuesField("field", newBytesRef("hello")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -232,7 +232,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
Document doc = new Document();
doc.add(new NumericDocValuesField("foo", 0));
- doc.add(new SortedDocValuesField("foo", new BytesRef("hello")));
+ doc.add(new SortedDocValuesField("foo", newBytesRef("hello")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -255,7 +255,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
w.addDocument(doc);
Document doc2 = new Document();
- doc2.add(new SortedDocValuesField("foo", new BytesRef("hello")));
+ doc2.add(new SortedDocValuesField("foo", newBytesRef("hello")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -278,10 +278,10 @@ public class TestDocValuesIndexing extends LuceneTestCase {
iwc.setMergePolicy(newLogMergePolicy());
IndexWriter iwriter = new IndexWriter(directory, iwc);
Document doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("foo!")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("foo!")));
iwriter.addDocument(doc);
- doc.add(new SortedDocValuesField("dv", new BytesRef("bar!")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("bar!")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -304,10 +304,10 @@ public class TestDocValuesIndexing extends LuceneTestCase {
iwc.setMergePolicy(newLogMergePolicy());
IndexWriter iwriter = new IndexWriter(directory, iwc);
Document doc = new Document();
- doc.add(new BinaryDocValuesField("dv", new BytesRef("foo!")));
+ doc.add(new BinaryDocValuesField("dv", newBytesRef("foo!")));
iwriter.addDocument(doc);
- doc.add(new BinaryDocValuesField("dv", new BytesRef("bar!")));
+ doc.add(new BinaryDocValuesField("dv", newBytesRef("bar!")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -357,12 +357,12 @@ public class TestDocValuesIndexing extends LuceneTestCase {
iwc.setMergePolicy(newLogMergePolicy());
IndexWriter iwriter = new IndexWriter(directory, iwc);
Document doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("just fine")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("just fine")));
iwriter.addDocument(doc);
Document hugeDoc = new Document();
byte bytes[] = new byte[100000];
- BytesRef b = new BytesRef(bytes);
+ BytesRef b = newBytesRef(bytes);
random().nextBytes(bytes);
hugeDoc.add(new SortedDocValuesField("dv", b));
expectThrows(
@@ -387,12 +387,12 @@ public class TestDocValuesIndexing extends LuceneTestCase {
iwc.setMergePolicy(newLogMergePolicy());
IndexWriter iwriter = new IndexWriter(directory, iwc);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("dv", new BytesRef("just fine")));
+ doc.add(new SortedSetDocValuesField("dv", newBytesRef("just fine")));
iwriter.addDocument(doc);
Document hugeDoc = new Document();
byte bytes[] = new byte[100000];
- BytesRef b = new BytesRef(bytes);
+ BytesRef b = newBytesRef(bytes);
random().nextBytes(bytes);
hugeDoc.add(new SortedSetDocValuesField("dv", b));
expectThrows(
@@ -418,7 +418,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
w.commit();
Document doc2 = new Document();
- doc2.add(new SortedDocValuesField("foo", new BytesRef("hello")));
+ doc2.add(new SortedDocValuesField("foo", newBytesRef("hello")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -439,7 +439,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
w.deleteAll();
doc = new Document();
- doc.add(new SortedDocValuesField("foo", new BytesRef("hello")));
+ doc.add(new SortedDocValuesField("foo", newBytesRef("hello")));
w.addDocument(doc);
w.close();
dir.close();
@@ -473,7 +473,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
IndexWriter w2 = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
Document doc2 = new Document();
- doc2.add(new SortedDocValuesField("foo", new BytesRef("hello")));
+ doc2.add(new SortedDocValuesField("foo", newBytesRef("hello")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -488,14 +488,14 @@ public class TestDocValuesIndexing extends LuceneTestCase {
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("foo", new BytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("foo", newBytesRef("foo")));
w.addDocument(doc);
w.close();
Document doc2 = new Document();
IndexWriter w2 = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
doc2.add(new StringField("foo", "bar", Field.Store.NO));
- doc2.add(new BinaryDocValuesField("foo", new BytesRef("foo")));
+ doc2.add(new BinaryDocValuesField("foo", newBytesRef("foo")));
// NOTE: this case follows a different code path inside
// DefaultIndexingChain/FieldInfos, because the field (foo)
// is first added without DocValues:
@@ -514,14 +514,14 @@ public class TestDocValuesIndexing extends LuceneTestCase {
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("foo", new BytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("foo", newBytesRef("foo")));
w.addDocument(doc);
w.close();
Document doc2 = new Document();
IndexWriter w2 = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
doc2.add(new StringField("foo", "bar", Field.Store.NO));
- doc2.add(new BinaryDocValuesField("foo", new BytesRef("foo")));
+ doc2.add(new BinaryDocValuesField("foo", newBytesRef("foo")));
// NOTE: this case follows a different code path inside
// DefaultIndexingChain/FieldInfos, because the field (foo)
// is first added without DocValues:
@@ -550,11 +550,11 @@ public class TestDocValuesIndexing extends LuceneTestCase {
for (int i = 0; i < 3; i++) {
Field field;
if (i == 0) {
- field = new SortedDocValuesField("foo", new BytesRef("hello"));
+ field = new SortedDocValuesField("foo", newBytesRef("hello"));
} else if (i == 1) {
field = new NumericDocValuesField("foo", 0);
} else {
- field = new BinaryDocValuesField("foo", new BytesRef("bazz"));
+ field = new BinaryDocValuesField("foo", newBytesRef("bazz"));
}
final Document doc = new Document();
doc.add(field);
@@ -601,7 +601,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
Directory dir2 = newDirectory();
IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig(new MockAnalyzer(random())));
doc = new Document();
- doc.add(new SortedDocValuesField("foo", new BytesRef("hello")));
+ doc.add(new SortedDocValuesField("foo", newBytesRef("hello")));
w2.addDocument(doc);
w2.close();
@@ -632,7 +632,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
doc.add(new NumericDocValuesField("dv", 0L));
writer.addDocument(doc);
Document doc2 = new Document();
- doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc2.add(new SortedDocValuesField("dv", newBytesRef("foo")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -658,7 +658,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer2 = new IndexWriter(dir, conf);
Document doc2 = new Document();
- doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc2.add(new SortedDocValuesField("dv", newBytesRef("foo")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -682,7 +682,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
writer = new IndexWriter(dir, conf);
writer.deleteAll();
doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("foo")));
writer.addDocument(doc);
writer.close();
dir.close();
@@ -697,7 +697,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
writer.addDocument(doc);
writer.deleteAll();
doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("foo")));
writer.addDocument(doc);
writer.close();
dir.close();
@@ -713,7 +713,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
writer.commit();
writer.deleteAll();
doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("foo")));
writer.addDocument(doc);
writer.close();
dir.close();
@@ -731,7 +731,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(dir, conf);
doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("foo")));
writer.addDocument(doc);
writer.close();
dir.close();
@@ -750,7 +750,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer2 = new IndexWriter(dir2, conf);
doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("foo")));
writer2.addDocument(doc);
expectThrows(
IllegalArgumentException.class,
@@ -776,7 +776,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer2 = new IndexWriter(dir2, conf);
doc = new Document();
- doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("dv", newBytesRef("foo")));
writer2.addDocument(doc);
DirectoryReader reader = DirectoryReader.open(dir);
expectThrows(
@@ -806,7 +806,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
IndexWriter writer2 = new IndexWriter(dir2, conf);
writer2.addIndexes(dir);
Document doc2 = new Document();
- doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc2.add(new SortedDocValuesField("dv", newBytesRef("foo")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -834,7 +834,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
TestUtil.addIndexesSlowly(writer2, reader);
reader.close();
Document doc2 = new Document();
- doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+ doc2.add(new SortedDocValuesField("dv", newBytesRef("foo")));
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -861,7 +861,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {
writer.commit();
Document doc2 = new Document();
- doc2.add(new BinaryDocValuesField("f", new BytesRef("mock")));
+ doc2.add(new BinaryDocValuesField("f", newBytesRef("mock")));
expectThrows(
IllegalArgumentException.class,
() -> {
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java b/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java
index 87ee9a8d196..05de14dbe5f 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java
@@ -64,7 +64,7 @@ public class TestDocsAndPositions extends LuceneTestCase {
int num = atLeast(13);
for (int i = 0; i < num; i++) {
- BytesRef bytes = new BytesRef("1");
+ BytesRef bytes = newBytesRef("1");
IndexReaderContext topReaderContext = reader.getContext();
for (LeafReaderContext leafReaderContext : topReaderContext.leaves()) {
PostingsEnum docsAndPosEnum = getDocsAndPositions(leafReaderContext.reader(), bytes);
@@ -150,7 +150,7 @@ public class TestDocsAndPositions extends LuceneTestCase {
int num = atLeast(13);
for (int i = 0; i < num; i++) {
- BytesRef bytes = new BytesRef("" + term);
+ BytesRef bytes = newBytesRef("" + term);
IndexReaderContext topReaderContext = reader.getContext();
for (LeafReaderContext leafReaderContext : topReaderContext.leaves()) {
PostingsEnum docsAndPosEnum = getDocsAndPositions(leafReaderContext.reader(), bytes);
@@ -238,7 +238,7 @@ public class TestDocsAndPositions extends LuceneTestCase {
int num = atLeast(13);
for (int i = 0; i < num; i++) {
- BytesRef bytes = new BytesRef("" + term);
+ BytesRef bytes = newBytesRef("" + term);
IndexReaderContext topReaderContext = reader.getContext();
for (LeafReaderContext context : topReaderContext.leaves()) {
int maxDoc = context.reader().maxDoc();
@@ -321,7 +321,7 @@ public class TestDocsAndPositions extends LuceneTestCase {
int num = atLeast(13);
for (int i = 0; i < num; i++) {
- BytesRef bytes = new BytesRef("even");
+ BytesRef bytes = newBytesRef("even");
IndexReaderContext topReaderContext = reader.getContext();
for (LeafReaderContext leafReaderContext : topReaderContext.leaves()) {
@@ -365,14 +365,14 @@ public class TestDocsAndPositions extends LuceneTestCase {
DirectoryReader reader = writer.getReader();
LeafReader r = getOnlyLeafReader(reader);
PostingsEnum disi =
- TestUtil.docs(random(), r, "foo", new BytesRef("bar"), null, PostingsEnum.NONE);
+ TestUtil.docs(random(), r, "foo", newBytesRef("bar"), null, PostingsEnum.NONE);
int docid = disi.docID();
assertEquals(-1, docid);
assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
// now reuse and check again
TermsEnum te = r.terms("foo").iterator();
- assertTrue(te.seekExact(new BytesRef("bar")));
+ assertTrue(te.seekExact(newBytesRef("bar")));
disi = TestUtil.docs(random(), te, disi, PostingsEnum.NONE);
docid = disi.docID();
assertEquals(-1, docid);
@@ -397,7 +397,7 @@ public class TestDocsAndPositions extends LuceneTestCase {
// now reuse and check again
TermsEnum te = r.terms("foo").iterator();
- assertTrue(te.seekExact(new BytesRef("bar")));
+ assertTrue(te.seekExact(newBytesRef("bar")));
disi = te.postings(disi, PostingsEnum.ALL);
docid = disi.docID();
assertEquals(-1, docid);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java b/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java
index fd431a16b48..332330a36af 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java
@@ -426,10 +426,10 @@ public class TestNumericDocValuesUpdates extends LuceneTestCase {
Document doc = new Document();
doc.add(new StringField("dvUpdateKey", "dv", Store.NO));
doc.add(new NumericDocValuesField("ndv", i));
- doc.add(new BinaryDocValuesField("bdv", new BytesRef(Integer.toString(i))));
- doc.add(new SortedDocValuesField("sdv", new BytesRef(Integer.toString(i))));
- doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(Integer.toString(i))));
- doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(Integer.toString(i * 2))));
+ doc.add(new BinaryDocValuesField("bdv", newBytesRef(Integer.toString(i))));
+ doc.add(new SortedDocValuesField("sdv", newBytesRef(Integer.toString(i))));
+ doc.add(new SortedSetDocValuesField("ssdv", newBytesRef(Integer.toString(i))));
+ doc.add(new SortedSetDocValuesField("ssdv", newBytesRef(Integer.toString(i * 2))));
writer.addDocument(doc);
}
writer.commit();
@@ -449,10 +449,10 @@ public class TestNumericDocValuesUpdates extends LuceneTestCase {
assertEquals(17, ndv.longValue());
assertEquals(i, bdv.nextDoc());
BytesRef term = bdv.binaryValue();
- assertEquals(new BytesRef(Integer.toString(i)), term);
+ assertEquals(newBytesRef(Integer.toString(i)), term);
assertEquals(i, sdv.nextDoc());
term = sdv.lookupOrd(sdv.ordValue());
- assertEquals(new BytesRef(Integer.toString(i)), term);
+ assertEquals(newBytesRef(Integer.toString(i)), term);
assertEquals(i, ssdv.nextDoc());
long ord = ssdv.nextOrd();
@@ -594,7 +594,7 @@ public class TestNumericDocValuesUpdates extends LuceneTestCase {
Document doc = new Document();
doc.add(new StringField("key", "doc", Store.NO));
doc.add(new NumericDocValuesField("ndv", 5));
- doc.add(new SortedDocValuesField("sorted", new BytesRef("value")));
+ doc.add(new SortedDocValuesField("sorted", newBytesRef("value")));
writer.addDocument(doc); // flushed document
writer.commit();
writer.addDocument(doc); // in-memory document
@@ -611,7 +611,7 @@ public class TestNumericDocValuesUpdates extends LuceneTestCase {
assertEquals(17, ndv.longValue());
assertEquals(i, sdv.nextDoc());
final BytesRef term = sdv.lookupOrd(sdv.ordValue());
- assertEquals(new BytesRef("value"), term);
+ assertEquals(newBytesRef("value"), term);
}
reader.close();
@@ -1614,7 +1614,7 @@ public class TestNumericDocValuesUpdates extends LuceneTestCase {
// update all doc values
long value = random().nextInt();
for (int i = 0; i < numDocs; i++) {
- Term term = new Term("id", new BytesRef(Integer.toString(i)));
+ Term term = new Term("id", newBytesRef(Integer.toString(i)));
writer.updateDocValues(term, new NumericDocValuesField("ndv", value));
}
@@ -1683,7 +1683,7 @@ public class TestNumericDocValuesUpdates extends LuceneTestCase {
// update some docs to a random value
long value = random().nextInt();
- Term term = new Term("id", new BytesRef(Integer.toString(random().nextInt(numDocs) * 2)));
+ Term term = new Term("id", newBytesRef(Integer.toString(random().nextInt(numDocs) * 2)));
writer.updateDocValues(
term,
new NumericDocValuesField("ndv", value),
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.java b/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.java
index 096782b844e..5e26dda3cf6 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.java
@@ -106,9 +106,9 @@ public class TestTermsEnum extends LuceneTestCase {
if (random().nextBoolean()) {
// likely fake term
if (random().nextBoolean()) {
- target = new BytesRef(TestUtil.randomSimpleString(random()));
+ target = newBytesRef(TestUtil.randomSimpleString(random()));
} else {
- target = new BytesRef(TestUtil.randomRealisticUnicodeString(random()));
+ target = newBytesRef(TestUtil.randomRealisticUnicodeString(random()));
}
exists = "likely not";
} else {
@@ -179,7 +179,7 @@ public class TestTermsEnum extends LuceneTestCase {
}
for (String s2 : terms) {
doc.add(newStringField("f", s2, Field.Store.NO));
- termToID.put(new BytesRef(s2), id);
+ termToID.put(newBytesRef(s2), id);
}
w.addDocument(doc);
terms.clear();
@@ -223,7 +223,7 @@ public class TestTermsEnum extends LuceneTestCase {
{
int upto = 0;
for (String s : terms) {
- final BytesRef b = new BytesRef(s);
+ final BytesRef b = newBytesRef(s);
termsArray[upto++] = b;
termsSet.add(b);
}
@@ -275,7 +275,7 @@ public class TestTermsEnum extends LuceneTestCase {
s2 = getRandomString();
}
acceptTerms.add(s2);
- sortedAcceptTerms.add(new BytesRef(s2));
+ sortedAcceptTerms.add(newBytesRef(s2));
}
a = Automata.makeStringUnion(sortedAcceptTerms);
}
@@ -286,7 +286,7 @@ public class TestTermsEnum extends LuceneTestCase {
final Set<BytesRef> acceptTermsSet = new HashSet<>();
int upto = 0;
for (String s : acceptTerms) {
- final BytesRef b = new BytesRef(s);
+ final BytesRef b = newBytesRef(s);
acceptTermsArray[upto++] = b;
acceptTermsSet.add(b);
assertTrue(accepts(c, b));
@@ -598,7 +598,7 @@ public class TestTermsEnum extends LuceneTestCase {
// sugar
private boolean seekExact(TermsEnum te, String term) throws IOException {
- return te.seekExact(new BytesRef(term));
+ return te.seekExact(newBytesRef(term));
}
// sugar
@@ -615,7 +615,7 @@ public class TestTermsEnum extends LuceneTestCase {
BytesRef t = null;
while (true) {
final String ts = getRandomString();
- t = new BytesRef(ts);
+ t = newBytesRef(ts);
if (Arrays.binarySearch(terms, t) < 0) {
return t;
}
@@ -635,7 +635,7 @@ public class TestTermsEnum extends LuceneTestCase {
private void testRandomSeeks(IndexReader r, String... validTermStrings) throws IOException {
final BytesRef[] validTerms = new BytesRef[validTermStrings.length];
for (int termIDX = 0; termIDX < validTermStrings.length; termIDX++) {
- validTerms[termIDX] = new BytesRef(validTermStrings[termIDX]);
+ validTerms[termIDX] = newBytesRef(validTermStrings[termIDX]);
}
Arrays.sort(validTerms);
if (VERBOSE) {
@@ -781,14 +781,14 @@ public class TestTermsEnum extends LuceneTestCase {
assertEquals(2, te.postings(null, PostingsEnum.NONE).nextDoc());
assertNull(te.next());
- te = terms.intersect(ca, new BytesRef("abc"));
+ te = terms.intersect(ca, newBytesRef("abc"));
assertEquals("bbb", te.next().utf8ToString());
assertEquals(1, te.postings(null, PostingsEnum.NONE).nextDoc());
assertEquals("ccc", te.next().utf8ToString());
assertEquals(2, te.postings(null, PostingsEnum.NONE).nextDoc());
assertNull(te.next());
- te = terms.intersect(ca, new BytesRef("aaa"));
+ te = terms.intersect(ca, newBytesRef("aaa"));
assertEquals("bbb", te.next().utf8ToString());
assertEquals(1, te.postings(null, PostingsEnum.NONE).nextDoc());
assertEquals("ccc", te.next().utf8ToString());
@@ -831,7 +831,7 @@ public class TestTermsEnum extends LuceneTestCase {
TermsEnum te;
// should seek to startTerm
- te = terms.intersect(ca, new BytesRef("aad"));
+ te = terms.intersect(ca, newBytesRef("aad"));
assertEquals("abd", te.next().utf8ToString());
assertEquals(1, te.postings(null, PostingsEnum.NONE).nextDoc());
assertEquals("acd", te.next().utf8ToString());
@@ -841,15 +841,15 @@ public class TestTermsEnum extends LuceneTestCase {
assertNull(te.next());
// should fail to find ceil label on second arc, rewind
- te = terms.intersect(ca, new BytesRef("add"));
+ te = terms.intersect(ca, newBytesRef("add"));
assertEquals("bcd", te.next().utf8ToString());
assertEquals(3, te.postings(null, PostingsEnum.NONE).nextDoc());
assertNull(te.next());
// should reach end
- te = terms.intersect(ca, new BytesRef("bcd"));
+ te = terms.intersect(ca, newBytesRef("bcd"));
assertNull(te.next());
- te = terms.intersect(ca, new BytesRef("ddd"));
+ te = terms.intersect(ca, newBytesRef("ddd"));
assertNull(te.next());
r.close();
@@ -899,7 +899,7 @@ public class TestTermsEnum extends LuceneTestCase {
assertNull(te.next());
// pass empty string
- te = terms.intersect(ca, new BytesRef(""));
+ te = terms.intersect(ca, newBytesRef(""));
assertEquals("abc", te.next().utf8ToString());
de = te.postings(null, PostingsEnum.NONE);
@@ -959,7 +959,7 @@ public class TestTermsEnum extends LuceneTestCase {
System.out.println(" shouldExist?=" + shouldExist);
}
- BytesRef termBytesRef = new BytesRef(term);
+ BytesRef termBytesRef = newBytesRef(term);
boolean actualResult = termsEnum.seekExact(termBytesRef);
assertEquals(shouldExist, actualResult);
@@ -1000,7 +1000,7 @@ public class TestTermsEnum extends LuceneTestCase {
Set<BytesRef> terms = new HashSet<BytesRef>();
int MAX_TERMS = atLeast(1000);
while (terms.size() < MAX_TERMS) {
- terms.add(new BytesRef(TestUtil.randomSimpleString(random(), 1, 40)));
+ terms.add(newBytesRef(TestUtil.randomSimpleString(random(), 1, 40)));
}
List<BytesRef> termsList = new ArrayList<>(terms);
StringBuilder sb = new StringBuilder();
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTermsHashPerField.java b/lucene/core/src/test/org/apache/lucene/index/TestTermsHashPerField.java
index 823dbb9aa84..73bee8a0baf 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestTermsHashPerField.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTermsHashPerField.java
@@ -130,22 +130,22 @@ public class TestTermsHashPerField extends LuceneTestCase {
TermsHashPerField hash = createNewHash(newCalled, addCalled);
hash.start(null, true);
- hash.add(new BytesRef("start"), 0); // tid = 0;
- hash.add(new BytesRef("foo"), 0); // tid = 1;
- hash.add(new BytesRef("bar"), 0); // tid = 2;
+ hash.add(newBytesRef("start"), 0); // tid = 0;
+ hash.add(newBytesRef("foo"), 0); // tid = 1;
+ hash.add(newBytesRef("bar"), 0); // tid = 2;
hash.finish();
- hash.add(new BytesRef("bar"), 1);
- hash.add(new BytesRef("foobar"), 1); // tid = 3;
- hash.add(new BytesRef("bar"), 1);
- hash.add(new BytesRef("bar"), 1);
- hash.add(new BytesRef("foobar"), 1);
- hash.add(new BytesRef("verylongfoobarbaz"), 1); // tid = 4;
+ hash.add(newBytesRef("bar"), 1);
+ hash.add(newBytesRef("foobar"), 1); // tid = 3;
+ hash.add(newBytesRef("bar"), 1);
+ hash.add(newBytesRef("bar"), 1);
+ hash.add(newBytesRef("foobar"), 1);
+ hash.add(newBytesRef("verylongfoobarbaz"), 1); // tid = 4;
hash.finish();
- hash.add(new BytesRef("verylongfoobarbaz"), 2);
- hash.add(new BytesRef("boom"), 2); // tid = 5;
+ hash.add(newBytesRef("verylongfoobarbaz"), 2);
+ hash.add(newBytesRef("boom"), 2); // tid = 5;
hash.finish();
- hash.add(new BytesRef("verylongfoobarbaz"), 3);
- hash.add(new BytesRef("end"), 3); // tid = 6;
+ hash.add(newBytesRef("verylongfoobarbaz"), 3);
+ hash.add(newBytesRef("end"), 3); // tid = 6;
hash.finish();
assertEquals(7, newCalled.get());
@@ -254,7 +254,7 @@ public class TestTermsHashPerField extends LuceneTestCase {
for (int i = 0; i < numStrings; i++) {
String randomString =
RandomStrings.randomRealisticUnicodeOfCodepointLengthBetween(random(), 1, 10);
- postingMap.putIfAbsent(new BytesRef(randomString), new Posting());
+ postingMap.putIfAbsent(newBytesRef(randomString), new Posting());
}
List<BytesRef> bytesRefs = Arrays.asList(postingMap.keySet().toArray(new BytesRef[0]));
Collections.sort(bytesRefs);
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java b/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java
index daa581791ff..fdbad355a30 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java
@@ -25,7 +25,6 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
/**
@@ -108,7 +107,7 @@ public class TestDateSort extends LuceneTestCase {
String dateTimeString = DateTools.timeToString(time, DateTools.Resolution.SECOND);
Field dateTimeField = newStringField(DATE_TIME_FIELD, dateTimeString, Field.Store.YES);
document.add(dateTimeField);
- document.add(new SortedDocValuesField(DATE_TIME_FIELD, new BytesRef(dateTimeString)));
+ document.add(new SortedDocValuesField(DATE_TIME_FIELD, newBytesRef(dateTimeString)));
return document;
}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java
index 862d72ae78a..8c01a0b949b 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java
@@ -27,7 +27,6 @@ import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.TestUtil;
@@ -109,9 +108,9 @@ public class TestDocValuesQueries extends LuceneTestCase {
byte[] encoded = new byte[Long.BYTES];
LongPoint.encodeDimension(value, encoded, 0);
if (sortedSet) {
- doc.add(new SortedSetDocValuesField("dv", new BytesRef(encoded)));
+ doc.add(new SortedSetDocValuesField("dv", newBytesRef(encoded)));
} else {
- doc.add(new SortedDocValuesField("dv", new BytesRef(encoded)));
+ doc.add(new SortedDocValuesField("dv", newBytesRef(encoded)));
}
doc.add(new LongPoint("idx", value));
}
@@ -149,16 +148,16 @@ public class TestDocValuesQueries extends LuceneTestCase {
q2 =
SortedSetDocValuesField.newSlowRangeQuery(
"dv",
- min == Long.MIN_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMin),
- max == Long.MAX_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMax),
+ min == Long.MIN_VALUE && random().nextBoolean() ? null : newBytesRef(encodedMin),
+ max == Long.MAX_VALUE && random().nextBoolean() ? null : newBytesRef(encodedMax),
includeMin,
includeMax);
} else {
q2 =
SortedDocValuesField.newSlowRangeQuery(
"dv",
- min == Long.MIN_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMin),
- max == Long.MAX_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMax),
+ min == Long.MIN_VALUE && random().nextBoolean() ? null : newBytesRef(encodedMin),
+ max == Long.MAX_VALUE && random().nextBoolean() ? null : newBytesRef(encodedMax),
includeMin,
includeMax);
}
@@ -205,23 +204,23 @@ public class TestDocValuesQueries extends LuceneTestCase {
Query q2 =
SortedSetDocValuesField.newSlowRangeQuery(
- "foo", new BytesRef("bar"), new BytesRef("baz"), true, true);
+ "foo", newBytesRef("bar"), newBytesRef("baz"), true, true);
QueryUtils.checkEqual(
q2,
SortedSetDocValuesField.newSlowRangeQuery(
- "foo", new BytesRef("bar"), new BytesRef("baz"), true, true));
+ "foo", newBytesRef("bar"), newBytesRef("baz"), true, true));
QueryUtils.checkUnequal(
q2,
SortedSetDocValuesField.newSlowRangeQuery(
- "foo", new BytesRef("baz"), new BytesRef("baz"), true, true));
+ "foo", newBytesRef("baz"), newBytesRef("baz"), true, true));
QueryUtils.checkUnequal(
q2,
SortedSetDocValuesField.newSlowRangeQuery(
- "foo", new BytesRef("bar"), new BytesRef("bar"), true, true));
+ "foo", newBytesRef("bar"), newBytesRef("bar"), true, true));
QueryUtils.checkUnequal(
q2,
SortedSetDocValuesField.newSlowRangeQuery(
- "quux", new BytesRef("bar"), new BytesRef("baz"), true, true));
+ "quux", newBytesRef("bar"), newBytesRef("baz"), true, true));
}
public void testToString() {
@@ -232,19 +231,19 @@ public class TestDocValuesQueries extends LuceneTestCase {
Query q2 =
SortedSetDocValuesField.newSlowRangeQuery(
- "foo", new BytesRef("bar"), new BytesRef("baz"), true, true);
+ "foo", newBytesRef("bar"), newBytesRef("baz"), true, true);
assertEquals("foo:[[62 61 72] TO [62 61 7a]]", q2.toString());
q2 =
SortedSetDocValuesField.newSlowRangeQuery(
- "foo", new BytesRef("bar"), new BytesRef("baz"), false, true);
+ "foo", newBytesRef("bar"), newBytesRef("baz"), false, true);
assertEquals("foo:{[62 61 72] TO [62 61 7a]]", q2.toString());
q2 =
SortedSetDocValuesField.newSlowRangeQuery(
- "foo", new BytesRef("bar"), new BytesRef("baz"), false, false);
+ "foo", newBytesRef("bar"), newBytesRef("baz"), false, false);
assertEquals("foo:{[62 61 72] TO [62 61 7a]}", q2.toString());
- q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), null, true, true);
+ q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", newBytesRef("bar"), null, true, true);
assertEquals("foo:[[62 61 72] TO *}", q2.toString());
- q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", null, new BytesRef("baz"), true, true);
+ q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", null, newBytesRef("baz"), true, true);
assertEquals("foo:{* TO [62 61 7a]]", q2.toString());
assertEquals("{* TO [62 61 7a]]", q2.toString("foo"));
assertEquals("foo:{* TO [62 61 7a]]", q2.toString("bar"));
@@ -263,14 +262,14 @@ public class TestDocValuesQueries extends LuceneTestCase {
SortedNumericDocValuesField.newSlowRangeQuery("foo", 2, 4),
SortedDocValuesField.newSlowRangeQuery(
"foo",
- new BytesRef("abc"),
- new BytesRef("bcd"),
+ newBytesRef("abc"),
+ newBytesRef("bcd"),
random().nextBoolean(),
random().nextBoolean()),
SortedSetDocValuesField.newSlowRangeQuery(
"foo",
- new BytesRef("abc"),
- new BytesRef("bcd"),
+ newBytesRef("abc"),
+ newBytesRef("bcd"),
random().nextBoolean(),
random().nextBoolean()))) {
Weight w = searcher.createWeight(searcher.rewrite(query), ScoreMode.COMPLETE, 1);
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
index 9b599556707..ad5ba73a4a4 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
@@ -845,12 +845,12 @@ public class TestFuzzyQuery extends LuceneTestCase {
}
private static void assertMatches(ByteRunAutomaton automaton, String text) {
- BytesRef b = new BytesRef(text);
+ BytesRef b = newBytesRef(text);
assertTrue(automaton.run(b.bytes, b.offset, b.length));
}
private static void assertNoMatches(ByteRunAutomaton automaton, String text) {
- BytesRef b = new BytesRef(text);
+ BytesRef b = newBytesRef(text);
assertFalse(automaton.run(b.bytes, b.offset, b.length));
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
index a627f3b2a43..4de410f8691 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
@@ -45,7 +45,6 @@ import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.NamedThreadFactory;
@@ -66,7 +65,7 @@ public class TestIndexSearcher extends LuceneTestCase {
Document doc = new Document();
doc.add(newStringField("field", Integer.toString(i), Field.Store.NO));
doc.add(newStringField("field2", Boolean.toString(i % 2 == 0), Field.Store.NO));
- doc.add(new SortedDocValuesField("field2", new BytesRef(Boolean.toString(i % 2 == 0))));
+ doc.add(new SortedDocValuesField("field2", newBytesRef(Boolean.toString(i % 2 == 0))));
iw.addDocument(doc);
if (random.nextBoolean()) {
@@ -100,7 +99,7 @@ public class TestIndexSearcher extends LuceneTestCase {
Query queries[] = new Query[] {new MatchAllDocsQuery(), new TermQuery(new Term("field", "1"))};
Sort sorts[] = new Sort[] {null, new Sort(new SortField("field2", SortField.Type.STRING))};
ScoreDoc afters[] =
- new ScoreDoc[] {null, new FieldDoc(0, 0f, new Object[] {new BytesRef("boo!")})};
+ new ScoreDoc[] {null, new FieldDoc(0, 0f, new Object[] {newBytesRef("boo!")})};
for (IndexSearcher searcher : searchers) {
for (ScoreDoc after : afters) {
@@ -423,7 +422,7 @@ public class TestIndexSearcher extends LuceneTestCase {
Query queries[] = new Query[] {new MatchAllDocsQuery(), new TermQuery(new Term("field", "1"))};
Sort sorts[] = new Sort[] {null, new Sort(new SortField("field2", SortField.Type.STRING))};
ScoreDoc afters[] =
- new ScoreDoc[] {null, new FieldDoc(0, 0f, new Object[] {new BytesRef("boo!")})};
+ new ScoreDoc[] {null, new FieldDoc(0, 0f, new Object[] {newBytesRef("boo!")})};
for (ScoreDoc after : afters) {
for (Query query : queries) {
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java b/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java
index 7702be786ff..2c9e6661787 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java
@@ -34,7 +34,6 @@ import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
@@ -112,7 +111,7 @@ public class TestLiveFieldValues extends LuceneTestCase {
String.format(
Locale.ROOT, "%d_%04x", threadID, threadRandom.nextInt(idCount));
Integer field = threadRandom.nextInt(Integer.MAX_VALUE);
- doc.add(newStringField("id", new BytesRef(id), Field.Store.YES));
+ doc.add(newStringField("id", newBytesRef(id), Field.Store.YES));
doc.add(new StoredField("field", field.intValue()));
w.updateDocument(new Term("id", id), doc);
rt.add(id, field);
@@ -123,7 +122,7 @@ public class TestLiveFieldValues extends LuceneTestCase {
if (allIDs.size() > 0 && threadRandom.nextDouble() <= deleteChance) {
String randomID = allIDs.get(threadRandom.nextInt(allIDs.size()));
- w.deleteDocuments(new Term("id", new BytesRef(randomID)));
+ w.deleteDocuments(new Term("id", newBytesRef(randomID)));
rt.delete(randomID);
values.put(randomID, missing);
}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
index 8deaacffc61..9968c8fc8b0 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
@@ -1025,7 +1025,7 @@ public class TestPhraseQuery extends LuceneTestCase {
for (String firstTerm : new String[] {"a", "b", "c"}) {
for (String secondTerm : new String[] {"a", "b", "c"}) {
- Query query = new PhraseQuery("foo", new BytesRef(firstTerm), new BytesRef(secondTerm));
+ Query query = new PhraseQuery("foo", newBytesRef(firstTerm), newBytesRef(secondTerm));
TopScoreDocCollector collector1 =
TopScoreDocCollector.create(10, null, Integer.MAX_VALUE); // COMPLETE
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 54134948ab0..1c1d0a3e34a 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
@@ -965,7 +965,7 @@ public class TestPointQueries extends LuceneTestCase {
if (bytes == null) {
return "null";
}
- return new BytesRef(bytes).toString();
+ return newBytesRef(bytes).toString();
}
private static boolean matches(int bytesPerDim, byte[][] lower, byte[][] upper, byte[][] value) {
@@ -2091,7 +2091,7 @@ public class TestPointQueries extends LuceneTestCase {
new PointInSetQuery.Stream() {
@Override
public BytesRef next() {
- return new BytesRef(new byte[3]);
+ return newBytesRef(new byte[3]);
}
}) {
@Override
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom2.java b/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom2.java
index 1c9d4712b81..901d539aae5 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom2.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom2.java
@@ -69,14 +69,14 @@ public class TestRegexpRandom2 extends LuceneTestCase {
Document doc = new Document();
Field field = newStringField(fieldName, "", Field.Store.NO);
doc.add(field);
- Field dvField = new SortedDocValuesField(fieldName, new BytesRef());
+ Field dvField = new SortedDocValuesField(fieldName, newBytesRef());
doc.add(dvField);
List<String> terms = new ArrayList<>();
int num = atLeast(200);
for (int i = 0; i < num; i++) {
String s = TestUtil.randomUnicodeString(random());
field.setStringValue(s);
- dvField.setBytesValue(new BytesRef(s));
+ dvField.setBytesValue(newBytesRef(s));
terms.add(s);
writer.addDocument(doc);
}
@@ -124,7 +124,7 @@ public class TestRegexpRandom2 extends LuceneTestCase {
private SimpleAutomatonTermsEnum(TermsEnum tenum) {
super(tenum);
- setInitialSeekTerm(new BytesRef(""));
+ setInitialSeekTerm(newBytesRef(""));
}
@Override
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java
index 448e28d9a1e..f94d932641d 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java
@@ -27,7 +27,6 @@ import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
/*
@@ -86,11 +85,11 @@ public class TestSort extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedDocValuesField("value", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("value", newBytesRef("foo")));
doc.add(newStringField("value", "foo", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("value", "bar", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -114,11 +113,11 @@ public class TestSort extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("value", "bar", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedDocValuesField("value", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("value", newBytesRef("foo")));
doc.add(newStringField("value", "foo", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -142,11 +141,11 @@ public class TestSort extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new BinaryDocValuesField("value", new BytesRef("foo")));
+ doc.add(new BinaryDocValuesField("value", newBytesRef("foo")));
doc.add(newStringField("value", "foo", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new BinaryDocValuesField("value", new BytesRef("bar")));
+ doc.add(new BinaryDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("value", "bar", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -170,11 +169,11 @@ public class TestSort extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new BinaryDocValuesField("value", new BytesRef("bar")));
+ doc.add(new BinaryDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("value", "bar", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new BinaryDocValuesField("value", new BytesRef("foo")));
+ doc.add(new BinaryDocValuesField("value", newBytesRef("foo")));
doc.add(newStringField("value", "foo", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -776,25 +775,25 @@ public class TestSort extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedDocValuesField("value1", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("value1", newBytesRef("foo")));
doc.add(new NumericDocValuesField("value2", 0));
doc.add(newStringField("value1", "foo", Field.Store.YES));
doc.add(newStringField("value2", "0", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedDocValuesField("value1", new BytesRef("bar")));
+ doc.add(new SortedDocValuesField("value1", newBytesRef("bar")));
doc.add(new NumericDocValuesField("value2", 1));
doc.add(newStringField("value1", "bar", Field.Store.YES));
doc.add(newStringField("value2", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedDocValuesField("value1", new BytesRef("bar")));
+ doc.add(new SortedDocValuesField("value1", newBytesRef("bar")));
doc.add(new NumericDocValuesField("value2", 0));
doc.add(newStringField("value1", "bar", Field.Store.YES));
doc.add(newStringField("value2", "0", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedDocValuesField("value1", new BytesRef("foo")));
+ doc.add(new SortedDocValuesField("value1", newBytesRef("foo")));
doc.add(new NumericDocValuesField("value2", 1));
doc.add(newStringField("value1", "foo", Field.Store.YES));
doc.add(newStringField("value2", "1", Field.Store.YES));
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
index d4a6ca6361f..b2f6e5b3f86 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
@@ -22,7 +22,6 @@ import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
@@ -37,12 +36,12 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -67,12 +66,12 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -100,12 +99,12 @@ public class TestSortedSetSelector extends LuceneTestCase {
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "3", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -137,12 +136,12 @@ public class TestSortedSetSelector extends LuceneTestCase {
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "3", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -171,11 +170,11 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -199,14 +198,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -230,14 +229,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -264,14 +263,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
doc.add(newStringField("id", "3", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -302,14 +301,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
doc.add(newStringField("id", "3", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -337,11 +336,11 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -365,14 +364,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -396,14 +395,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -430,14 +429,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
doc.add(newStringField("id", "3", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -468,14 +467,14 @@ public class TestSortedSetSelector extends LuceneTestCase {
doc.add(newStringField("id", "3", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("a")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("c")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("d")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("a")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("c")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("d")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("b")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("b")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -503,11 +502,11 @@ public class TestSortedSetSelector extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java
index b338d5c659c..b9ca0c2316f 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java
@@ -24,7 +24,6 @@ import org.apache.lucene.index.MultiReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
/** Simple tests for SortedSetSortField, indexing the sortedset up front */
@@ -68,12 +67,12 @@ public class TestSortedSetSortField extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
@@ -96,12 +95,12 @@ public class TestSortedSetSortField extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
@@ -125,12 +124,12 @@ public class TestSortedSetSortField extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
@@ -160,12 +159,12 @@ public class TestSortedSetSortField extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("foo")));
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("foo")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
@@ -195,11 +194,11 @@ public class TestSortedSetSortField extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
- doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
+ doc.add(new SortedSetDocValuesField("value", newBytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc);
IndexReader ir = writer.getReader();
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTermInSetQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestTermInSetQuery.java
index 8ae811d3fdc..0887b4edeef 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestTermInSetQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestTermInSetQuery.java
@@ -56,7 +56,7 @@ public class TestTermInSetQuery extends LuceneTestCase {
final int numTerms = TestUtil.nextInt(random(), 1, 1 << TestUtil.nextInt(random(), 1, 10));
for (int i = 0; i < numTerms; ++i) {
final String value = TestUtil.randomAnalysisString(random(), 10, true);
- allTerms.add(new BytesRef(value));
+ allTerms.add(newBytesRef(value));
}
Directory dir = newDirectory();
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
@@ -123,8 +123,8 @@ public class TestTermInSetQuery extends LuceneTestCase {
Set<BytesRef> uniqueTerms = new HashSet<>();
for (int i = 0; i < num; i++) {
String string = TestUtil.randomRealisticUnicodeString(random());
- terms.add(new BytesRef(string));
- uniqueTerms.add(new BytesRef(string));
+ terms.add(newBytesRef(string));
+ uniqueTerms.add(newBytesRef(string));
TermInSetQuery left = new TermInSetQuery("field", uniqueTerms);
Collections.shuffle(terms, random());
TermInSetQuery right = new TermInSetQuery("field", terms);
@@ -139,40 +139,40 @@ public class TestTermInSetQuery extends LuceneTestCase {
}
}
- TermInSetQuery tq1 = new TermInSetQuery("thing", new BytesRef("apple"));
- TermInSetQuery tq2 = new TermInSetQuery("thing", new BytesRef("orange"));
+ TermInSetQuery tq1 = new TermInSetQuery("thing", newBytesRef("apple"));
+ TermInSetQuery tq2 = new TermInSetQuery("thing", newBytesRef("orange"));
assertFalse(tq1.hashCode() == tq2.hashCode());
// different fields with the same term should have differing hashcodes
- tq1 = new TermInSetQuery("thing", new BytesRef("apple"));
- tq2 = new TermInSetQuery("thing2", new BytesRef("apple"));
+ tq1 = new TermInSetQuery("thing", newBytesRef("apple"));
+ tq2 = new TermInSetQuery("thing2", newBytesRef("apple"));
assertFalse(tq1.hashCode() == tq2.hashCode());
}
public void testSimpleEquals() {
// Two terms with the same hash code
assertEquals("AaAaBB".hashCode(), "BBBBBB".hashCode());
- TermInSetQuery left = new TermInSetQuery("id", new BytesRef("AaAaAa"), new BytesRef("AaAaBB"));
- TermInSetQuery right = new TermInSetQuery("id", new BytesRef("AaAaAa"), new BytesRef("BBBBBB"));
+ TermInSetQuery left = new TermInSetQuery("id", newBytesRef("AaAaAa"), newBytesRef("AaAaBB"));
+ TermInSetQuery right = new TermInSetQuery("id", newBytesRef("AaAaAa"), newBytesRef("BBBBBB"));
assertFalse(left.equals(right));
}
public void testToString() {
TermInSetQuery termsQuery =
- new TermInSetQuery("field1", new BytesRef("a"), new BytesRef("b"), new BytesRef("c"));
+ new TermInSetQuery("field1", newBytesRef("a"), newBytesRef("b"), newBytesRef("c"));
assertEquals("field1:(a b c)", termsQuery.toString());
}
public void testDedup() {
- Query query1 = new TermInSetQuery("foo", new BytesRef("bar"));
- Query query2 = new TermInSetQuery("foo", new BytesRef("bar"), new BytesRef("bar"));
+ Query query1 = new TermInSetQuery("foo", newBytesRef("bar"));
+ Query query2 = new TermInSetQuery("foo", newBytesRef("bar"), newBytesRef("bar"));
QueryUtils.checkEqual(query1, query2);
}
public void testOrderDoesNotMatter() {
// order of terms if different
- Query query1 = new TermInSetQuery("foo", new BytesRef("bar"), new BytesRef("baz"));
- Query query2 = new TermInSetQuery("foo", new BytesRef("baz"), new BytesRef("bar"));
+ Query query1 = new TermInSetQuery("foo", newBytesRef("bar"), newBytesRef("baz"));
+ Query query2 = new TermInSetQuery("foo", newBytesRef("baz"), newBytesRef("bar"));
QueryUtils.checkEqual(query1, query2);
}
@@ -180,7 +180,7 @@ public class TestTermInSetQuery extends LuceneTestCase {
List<BytesRef> terms = new ArrayList<>();
final int numTerms = 10000 + random().nextInt(1000);
for (int i = 0; i < numTerms; ++i) {
- terms.add(new BytesRef(RandomStrings.randomUnicodeOfLength(random(), 10)));
+ terms.add(newBytesRef(RandomStrings.randomUnicodeOfLength(random(), 10)));
}
TermInSetQuery query = new TermInSetQuery("f", terms);
final long actualRamBytesUsed = RamUsageTester.sizeOf(query);
@@ -274,8 +274,7 @@ public class TestTermInSetQuery extends LuceneTestCase {
final int numTerms =
TestUtil.nextInt(random(), TermInSetQuery.BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD + 1, 100);
for (int i = 0; i < numTerms; ++i) {
- final BytesRef term =
- new BytesRef(RandomStrings.randomUnicodeOfCodepointLength(random(), 10));
+ final BytesRef term = newBytesRef(RandomStrings.randomUnicodeOfCodepointLength(random(), 10));
terms.add(term);
}
@@ -289,12 +288,12 @@ public class TestTermInSetQuery extends LuceneTestCase {
public void testBinaryToString() {
TermInSetQuery query =
- new TermInSetQuery("field", new BytesRef(new byte[] {(byte) 0xff, (byte) 0xfe}));
+ new TermInSetQuery("field", newBytesRef(new byte[] {(byte) 0xff, (byte) 0xfe}));
assertEquals("field:([ff fe])", query.toString());
}
public void testIsConsideredCostlyByQueryCache() throws IOException {
- TermInSetQuery query = new TermInSetQuery("foo", new BytesRef("bar"), new BytesRef("baz"));
+ TermInSetQuery query = new TermInSetQuery("foo", newBytesRef("bar"), newBytesRef("baz"));
UsageTrackingQueryCachingPolicy policy = new UsageTrackingQueryCachingPolicy();
assertFalse(policy.shouldCache(query));
policy.onUse(query);
@@ -305,13 +304,13 @@ public class TestTermInSetQuery extends LuceneTestCase {
public void testVisitor() {
// singleton reports back to consumeTerms()
- TermInSetQuery singleton = new TermInSetQuery("field", new BytesRef("term1"));
+ TermInSetQuery singleton = new TermInSetQuery("field", newBytesRef("term1"));
singleton.visit(
new QueryVisitor() {
@Override
public void consumeTerms(Query query, Term... terms) {
assertEquals(1, terms.length);
- assertEquals(new Term("field", new BytesRef("term1")), terms[0]);
+ assertEquals(new Term("field", newBytesRef("term1")), terms[0]);
}
@Override
@@ -324,7 +323,7 @@ public class TestTermInSetQuery extends LuceneTestCase {
// multiple values built into automaton
List<BytesRef> terms = new ArrayList<>();
for (int i = 0; i < 100; i++) {
- terms.add(new BytesRef("term" + i));
+ terms.add(newBytesRef("term" + i));
}
TermInSetQuery t = new TermInSetQuery("field", terms);
t.visit(
@@ -338,7 +337,7 @@ public class TestTermInSetQuery extends LuceneTestCase {
public void consumeTermsMatching(
Query query, String field, Supplier<ByteRunAutomaton> automaton) {
ByteRunAutomaton a = automaton.get();
- BytesRef test = new BytesRef("nonmatching");
+ BytesRef test = newBytesRef("nonmatching");
assertFalse(a.run(test.bytes, test.offset, test.length));
for (BytesRef term : terms) {
assertTrue(a.run(term.bytes, term.offset, term.length));
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java b/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java
index 21ea5ed3a7a..be1c8f5cb52 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java
@@ -60,7 +60,6 @@ public class TestBytesRefHash extends LuceneTestCase {
}
/** Test method for {@link org.apache.lucene.util.BytesRefHash#size()}. */
- @Test
public void testSize() {
BytesRefBuilder ref = new BytesRefBuilder();
int num = atLeast(2);
@@ -86,7 +85,6 @@ public class TestBytesRefHash extends LuceneTestCase {
}
/** Test method for {@link org.apache.lucene.util.BytesRefHash#get(int, BytesRef)} . */
- @Test
public void testGet() {
BytesRefBuilder ref = new BytesRefBuilder();
BytesRef scratch = new BytesRef();
@@ -123,7 +121,6 @@ public class TestBytesRefHash extends LuceneTestCase {
}
/** Test method for {@link org.apache.lucene.util.BytesRefHash#compact()}. */
- @Test
public void testCompact() {
BytesRefBuilder ref = new BytesRefBuilder();
int num = atLeast(2);
@@ -162,7 +159,6 @@ public class TestBytesRefHash extends LuceneTestCase {
}
/** Test method for {@link org.apache.lucene.util.BytesRefHash#sort()}. */
- @Test
public void testSort() {
BytesRefBuilder ref = new BytesRefBuilder();
int num = atLeast(2);
@@ -197,7 +193,6 @@ public class TestBytesRefHash extends LuceneTestCase {
* Test method for {@link
* org.apache.lucene.util.BytesRefHash#add(org.apache.lucene.util.BytesRef)} .
*/
- @Test
public void testAdd() {
BytesRefBuilder ref = new BytesRefBuilder();
BytesRef scratch = new BytesRef();
@@ -234,7 +229,6 @@ public class TestBytesRefHash extends LuceneTestCase {
}
}
- @Test
public void testFind() throws Exception {
BytesRefBuilder ref = new BytesRefBuilder();
BytesRef scratch = new BytesRef();
@@ -271,7 +265,6 @@ public class TestBytesRefHash extends LuceneTestCase {
}
}
- @Test
public void testConcurrentAccessToBytesRefHash() throws Exception {
int num = atLeast(2);
for (int j = 0; j < num; j++) {
@@ -279,7 +272,7 @@ public class TestBytesRefHash extends LuceneTestCase {
List<String> strings = new ArrayList<>(numStrings);
for (int i = 0; i < numStrings; i++) {
final String str = TestUtil.randomRealisticUnicodeString(random(), 1, 1000);
- hash.add(new BytesRef(str));
+ hash.add(newBytesRef(str));
assertTrue(strings.add(str));
}
int hashSize = hash.size();
@@ -304,7 +297,7 @@ public class TestBytesRefHash extends LuceneTestCase {
throw new RuntimeException(e);
}
for (int k = 0; k < loops; k++) {
- BytesRef find = new BytesRef(strings.get(k % strings.size()));
+ BytesRef find = newBytesRef(strings.get(k % strings.size()));
int id = hash.find(find);
if (id < 0) {
notFound.incrementAndGet();
@@ -357,7 +350,6 @@ public class TestBytesRefHash extends LuceneTestCase {
}
/** Test method for {@link org.apache.lucene.util.BytesRefHash#addByPoolOffset(int)} . */
- @Test
public void testAddByPoolOffset() {
BytesRefBuilder ref = new BytesRefBuilder();
BytesRef scratch = new BytesRef();
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java b/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java
index 7bd7c3d05f4..7ec5d3f9406 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java
@@ -215,7 +215,7 @@ public class TestPagedBytes extends LuceneTestCase {
PagedBytes b = new PagedBytes(blockBits);
final int totalBytes = random().nextInt(10000);
for (long pointer = 0; pointer < totalBytes; ) {
- BytesRef bytes = new BytesRef(TestUtil.randomSimpleString(random(), 10));
+ BytesRef bytes = newBytesRef(TestUtil.randomSimpleString(random(), 10));
pointer = b.copyUsingLengthPrefix(bytes);
}
assertEquals(RamUsageTester.sizeOf(b), b.ramBytesUsed());
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java b/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
index beb3aeca27f..ea8b98fbe39 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
@@ -19,75 +19,75 @@ package org.apache.lucene.util;
public class TestStringHelper extends LuceneTestCase {
public void testBytesDifference() {
- BytesRef left = new BytesRef("foobar");
- BytesRef right = new BytesRef("foozo");
+ BytesRef left = newBytesRef("foobar");
+ BytesRef right = newBytesRef("foozo");
assertEquals(3, StringHelper.bytesDifference(left, right));
- assertEquals(2, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("for")));
- assertEquals(2, StringHelper.bytesDifference(new BytesRef("foo1234"), new BytesRef("for1234")));
- assertEquals(1, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("fz")));
- assertEquals(0, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("g")));
- assertEquals(3, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("food")));
+ assertEquals(2, StringHelper.bytesDifference(newBytesRef("foo"), newBytesRef("for")));
+ assertEquals(2, StringHelper.bytesDifference(newBytesRef("foo1234"), newBytesRef("for1234")));
+ assertEquals(1, StringHelper.bytesDifference(newBytesRef("foo"), newBytesRef("fz")));
+ assertEquals(0, StringHelper.bytesDifference(newBytesRef("foo"), newBytesRef("g")));
+ assertEquals(3, StringHelper.bytesDifference(newBytesRef("foo"), newBytesRef("food")));
// we can detect terms are out of order if we see a duplicate
expectThrows(
IllegalArgumentException.class,
() -> {
- StringHelper.bytesDifference(new BytesRef("ab"), new BytesRef("ab"));
+ StringHelper.bytesDifference(newBytesRef("ab"), newBytesRef("ab"));
});
}
public void testStartsWith() {
- BytesRef ref = new BytesRef("foobar");
- BytesRef slice = new BytesRef("foo");
+ BytesRef ref = newBytesRef("foobar");
+ BytesRef slice = newBytesRef("foo");
assertTrue(StringHelper.startsWith(ref, slice));
}
public void testEndsWith() {
- BytesRef ref = new BytesRef("foobar");
- BytesRef slice = new BytesRef("bar");
+ BytesRef ref = newBytesRef("foobar");
+ BytesRef slice = newBytesRef("bar");
assertTrue(StringHelper.endsWith(ref, slice));
}
public void testStartsWithWhole() {
- BytesRef ref = new BytesRef("foobar");
- BytesRef slice = new BytesRef("foobar");
+ BytesRef ref = newBytesRef("foobar");
+ BytesRef slice = newBytesRef("foobar");
assertTrue(StringHelper.startsWith(ref, slice));
}
public void testEndsWithWhole() {
- BytesRef ref = new BytesRef("foobar");
- BytesRef slice = new BytesRef("foobar");
+ BytesRef ref = newBytesRef("foobar");
+ BytesRef slice = newBytesRef("foobar");
assertTrue(StringHelper.endsWith(ref, slice));
}
public void testMurmurHash3() throws Exception {
// Hashes computed using murmur3_32 from https://code.google.com/p/pyfasthash
- assertEquals(0xf6a5c420, StringHelper.murmurhash3_x86_32(new BytesRef("foo"), 0));
- assertEquals(0xcd018ef6, StringHelper.murmurhash3_x86_32(new BytesRef("foo"), 16));
+ assertEquals(0xf6a5c420, StringHelper.murmurhash3_x86_32(newBytesRef("foo"), 0));
+ assertEquals(0xcd018ef6, StringHelper.murmurhash3_x86_32(newBytesRef("foo"), 16));
assertEquals(
0x111e7435,
StringHelper.murmurhash3_x86_32(
- new BytesRef(
+ newBytesRef(
"You want weapons? We're in a library! Books! The best weapons in the world!"),
0));
assertEquals(
0x2c628cd0,
StringHelper.murmurhash3_x86_32(
- new BytesRef(
+ newBytesRef(
"You want weapons? We're in a library! Books! The best weapons in the world!"),
3476));
}
public void testSortKeyLength() throws Exception {
- assertEquals(3, StringHelper.sortKeyLength(new BytesRef("foo"), new BytesRef("for")));
- assertEquals(3, StringHelper.sortKeyLength(new BytesRef("foo1234"), new BytesRef("for1234")));
- assertEquals(2, StringHelper.sortKeyLength(new BytesRef("foo"), new BytesRef("fz")));
- assertEquals(1, StringHelper.sortKeyLength(new BytesRef("foo"), new BytesRef("g")));
- assertEquals(4, StringHelper.sortKeyLength(new BytesRef("foo"), new BytesRef("food")));
+ assertEquals(3, StringHelper.sortKeyLength(newBytesRef("foo"), newBytesRef("for")));
+ assertEquals(3, StringHelper.sortKeyLength(newBytesRef("foo1234"), newBytesRef("for1234")));
+ assertEquals(2, StringHelper.sortKeyLength(newBytesRef("foo"), newBytesRef("fz")));
+ assertEquals(1, StringHelper.sortKeyLength(newBytesRef("foo"), newBytesRef("g")));
+ assertEquals(4, StringHelper.sortKeyLength(newBytesRef("foo"), newBytesRef("food")));
// we can detect terms are out of order if we see a duplicate
expectThrows(
IllegalArgumentException.class,
() -> {
- StringHelper.sortKeyLength(new BytesRef("ab"), new BytesRef("ab"));
+ StringHelper.sortKeyLength(newBytesRef("ab"), newBytesRef("ab"));
});
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
index b149cfa9055..065e47e27e8 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
@@ -102,12 +102,12 @@ public class TestUnicodeUtil extends LuceneTestCase {
assertcodePointCountThrowsAssertionOn(asByteArray('z', 0xf0, 0xa4, 0xad));
// Check some typical examples (multibyte).
- assertEquals(0, UnicodeUtil.codePointCount(new BytesRef(asByteArray())));
- assertEquals(3, UnicodeUtil.codePointCount(new BytesRef(asByteArray('z', 'z', 'z'))));
- assertEquals(2, UnicodeUtil.codePointCount(new BytesRef(asByteArray('z', 0xc2, 0xa2))));
- assertEquals(2, UnicodeUtil.codePointCount(new BytesRef(asByteArray('z', 0xe2, 0x82, 0xac))));
+ assertEquals(0, UnicodeUtil.codePointCount(newBytesRef(asByteArray())));
+ assertEquals(3, UnicodeUtil.codePointCount(newBytesRef(asByteArray('z', 'z', 'z'))));
+ assertEquals(2, UnicodeUtil.codePointCount(newBytesRef(asByteArray('z', 0xc2, 0xa2))));
+ assertEquals(2, UnicodeUtil.codePointCount(newBytesRef(asByteArray('z', 0xe2, 0x82, 0xac))));
assertEquals(
- 2, UnicodeUtil.codePointCount(new BytesRef(asByteArray('z', 0xf0, 0xa4, 0xad, 0xa2))));
+ 2, UnicodeUtil.codePointCount(newBytesRef(asByteArray('z', 0xf0, 0xa4, 0xad, 0xa2))));
// And do some random stuff.
int num = atLeast(50000);
@@ -117,7 +117,7 @@ public class TestUnicodeUtil extends LuceneTestCase {
final int utf8Len = UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8);
assertEquals(
s.codePointCount(0, s.length()),
- UnicodeUtil.codePointCount(new BytesRef(utf8, 0, utf8Len)));
+ UnicodeUtil.codePointCount(newBytesRef(utf8, 0, utf8Len)));
}
}
@@ -133,7 +133,7 @@ public class TestUnicodeUtil extends LuceneTestCase {
expectThrows(
IllegalArgumentException.class,
() -> {
- UnicodeUtil.codePointCount(new BytesRef(bytes));
+ UnicodeUtil.codePointCount(newBytesRef(bytes));
});
}
@@ -145,7 +145,7 @@ public class TestUnicodeUtil extends LuceneTestCase {
final byte[] utf8 = new byte[UnicodeUtil.maxUTF8Length(s.length())];
final int utf8Len = UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8);
utf32 = ArrayUtil.grow(utf32, utf8Len);
- final int utf32Len = UnicodeUtil.UTF8toUTF32(new BytesRef(utf8, 0, utf8Len), utf32);
+ final int utf32Len = UnicodeUtil.UTF8toUTF32(newBytesRef(utf8, 0, utf8Len), utf32);
int[] codePoints = s.codePoints().toArray();
if (!Arrays.equals(codePoints, 0, codePoints.length, utf32, 0, codePoints.length)) {
@@ -219,7 +219,7 @@ public class TestUnicodeUtil extends LuceneTestCase {
int num = atLeast(3989);
for (int i = 0; i < num; i++) {
String unicode = TestUtil.randomRealisticUnicodeString(random());
- BytesRef ref = new BytesRef(unicode);
+ BytesRef ref = newBytesRef(unicode);
CharsRefBuilder cRef = new CharsRefBuilder();
cRef.copyUTF8Bytes(ref);
assertEquals(cRef.toString(), unicode);
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
index 211e93b990c..c40891f4e4f 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
@@ -364,33 +364,33 @@ public class TestAutomaton extends LuceneTestCase {
}
public void testCommonSuffixEmpty() throws Exception {
- assertEquals(new BytesRef(), Operations.getCommonSuffixBytesRef(Automata.makeEmpty()));
+ assertEquals(newBytesRef(), Operations.getCommonSuffixBytesRef(Automata.makeEmpty()));
}
public void testCommonSuffixEmptyString() throws Exception {
- assertEquals(new BytesRef(), Operations.getCommonSuffixBytesRef(Automata.makeEmptyString()));
+ assertEquals(newBytesRef(), Operations.getCommonSuffixBytesRef(Automata.makeEmptyString()));
}
public void testCommonSuffixTrailingWildcard() throws Exception {
Automaton a = Operations.concatenate(Automata.makeString("boo"), Automata.makeAnyChar());
- assertEquals(new BytesRef(), Operations.getCommonSuffixBytesRef(a));
+ assertEquals(newBytesRef(), Operations.getCommonSuffixBytesRef(a));
}
public void testCommonSuffixLeadingKleenStar() throws Exception {
Automaton a = Operations.concatenate(Automata.makeAnyString(), Automata.makeString("boo"));
- assertEquals(new BytesRef("boo"), Operations.getCommonSuffixBytesRef(a));
+ assertEquals(newBytesRef("boo"), Operations.getCommonSuffixBytesRef(a));
}
public void testCommonSuffixTrailingKleenStar() throws Exception {
Automaton a = Operations.concatenate(Automata.makeString("boo"), Automata.makeAnyString());
- assertEquals(new BytesRef(), Operations.getCommonSuffixBytesRef(a));
+ assertEquals(newBytesRef(), Operations.getCommonSuffixBytesRef(a));
}
public void testCommonSuffixUnicode() throws Exception {
Automaton a =
Operations.concatenate(Automata.makeAnyString(), Automata.makeString("booπŸ˜‚πŸ˜‚πŸ˜‚"));
Automaton binary = new UTF32ToUTF8().convert(a);
- assertEquals(new BytesRef("booπŸ˜‚πŸ˜‚πŸ˜‚"), Operations.getCommonSuffixBytesRef(binary));
+ assertEquals(newBytesRef("booπŸ˜‚πŸ˜‚πŸ˜‚"), Operations.getCommonSuffixBytesRef(binary));
}
public void testReverseRandom1() throws Exception {
@@ -828,7 +828,7 @@ public class TestAutomaton extends LuceneTestCase {
Set<BytesRef> terms = new HashSet<>();
while (terms.size() < numTerms) {
- terms.add(new BytesRef(getRandomString()));
+ terms.add(newBytesRef(getRandomString()));
}
Automaton a = unionTerms(terms);
@@ -858,7 +858,7 @@ public class TestAutomaton extends LuceneTestCase {
System.out.println(" op=concat prefix");
}
Set<BytesRef> newTerms = new HashSet<>();
- BytesRef prefix = new BytesRef(getRandomString());
+ BytesRef prefix = newBytesRef(getRandomString());
BytesRefBuilder newTerm = new BytesRefBuilder();
for (BytesRef term : terms) {
newTerm.copyBytes(prefix);
@@ -875,7 +875,7 @@ public class TestAutomaton extends LuceneTestCase {
case 1:
// concatenate suffix
{
- BytesRef suffix = new BytesRef(getRandomString());
+ BytesRef suffix = newBytesRef(getRandomString());
if (VERBOSE) {
System.out.println(" op=concat suffix " + suffix);
}
@@ -921,7 +921,7 @@ public class TestAutomaton extends LuceneTestCase {
Set<BytesRef> newTerms = new HashSet<>();
int numNewTerms = random().nextInt(5);
while (newTerms.size() < numNewTerms) {
- newTerms.add(new BytesRef(getRandomString()));
+ newTerms.add(newBytesRef(getRandomString()));
}
terms.addAll(newTerms);
Automaton newA = unionTerms(newTerms);
@@ -937,7 +937,7 @@ public class TestAutomaton extends LuceneTestCase {
}
// NOTE: This can add a dead state:
a = Operations.optional(a);
- terms.add(new BytesRef());
+ terms.add(newBytesRef());
}
break;
@@ -954,7 +954,7 @@ public class TestAutomaton extends LuceneTestCase {
int numToRemove = TestUtil.nextInt(random(), 1, (terms.size() + 1) / 2);
while (toRemove.size() < numToRemove) {
int[] ints = rasl.getRandomAcceptedString(random());
- BytesRef term = new BytesRef(UnicodeUtil.newString(ints, 0, ints.length));
+ BytesRef term = newBytesRef(UnicodeUtil.newString(ints, 0, ints.length));
if (toRemove.contains(term) == false) {
toRemove.add(term);
}
@@ -1074,7 +1074,7 @@ public class TestAutomaton extends LuceneTestCase {
Set<BytesRef> newTerms = new HashSet<>();
for (BytesRef term : terms) {
newTerms.add(
- new BytesRef(new StringBuilder(term.utf8ToString()).reverse().toString()));
+ newBytesRef(new StringBuilder(term.utf8ToString()).reverse().toString()));
}
terms = newTerms;
}
@@ -1110,7 +1110,7 @@ public class TestAutomaton extends LuceneTestCase {
// Left-fill with 0s
s = prefix.substring(s.length()) + s;
}
- terms.add(new BytesRef(s));
+ terms.add(newBytesRef(s));
}
}
break;
@@ -1120,7 +1120,7 @@ public class TestAutomaton extends LuceneTestCase {
System.out.println(" op=remove the empty string");
}
a = Operations.minus(a, Automata.makeEmptyString(), DEFAULT_DETERMINIZE_WORK_LIMIT);
- terms.remove(new BytesRef());
+ terms.remove(newBytesRef());
break;
case 13:
@@ -1128,7 +1128,7 @@ public class TestAutomaton extends LuceneTestCase {
System.out.println(" op=add the empty string");
}
a = Operations.union(a, Automata.makeEmptyString());
- terms.add(new BytesRef());
+ terms.add(newBytesRef());
break;
case 14:
@@ -1140,7 +1140,7 @@ public class TestAutomaton extends LuceneTestCase {
int count = random().nextBoolean() ? 2 : 3;
Set<BytesRef> addTerms = new HashSet<>();
while (addTerms.size() < count) {
- addTerms.add(new BytesRef(getRandomString()));
+ addTerms.add(newBytesRef(getRandomString()));
}
if (VERBOSE) {
for (BytesRef term : addTerms) {
@@ -1352,50 +1352,50 @@ public class TestAutomaton extends LuceneTestCase {
// 0 (incl) - 00 (incl)
byte[] zeros = new byte[3];
Automaton a =
- makeBinaryInterval(new BytesRef(zeros, 0, 1), true, new BytesRef(zeros, 0, 2), true);
+ makeBinaryInterval(newBytesRef(zeros, 0, 1), true, newBytesRef(zeros, 0, 2), true);
assertTrue(Operations.isFinite(a));
- assertFalse(accepts(a, new BytesRef()));
- assertTrue(accepts(a, new BytesRef(zeros, 0, 1)));
- assertTrue(accepts(a, new BytesRef(zeros, 0, 2)));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 3)));
+ assertFalse(accepts(a, newBytesRef()));
+ assertTrue(accepts(a, newBytesRef(zeros, 0, 1)));
+ assertTrue(accepts(a, newBytesRef(zeros, 0, 2)));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 3)));
// '' (incl) - 00 (incl)
- a = makeBinaryInterval(new BytesRef(), true, new BytesRef(zeros, 0, 2), true);
+ a = makeBinaryInterval(newBytesRef(), true, newBytesRef(zeros, 0, 2), true);
assertTrue(Operations.isFinite(a));
- assertTrue(accepts(a, new BytesRef()));
- assertTrue(accepts(a, new BytesRef(zeros, 0, 1)));
- assertTrue(accepts(a, new BytesRef(zeros, 0, 2)));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 3)));
+ assertTrue(accepts(a, newBytesRef()));
+ assertTrue(accepts(a, newBytesRef(zeros, 0, 1)));
+ assertTrue(accepts(a, newBytesRef(zeros, 0, 2)));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 3)));
// '' (excl) - 00 (incl)
- a = makeBinaryInterval(new BytesRef(), false, new BytesRef(zeros, 0, 2), true);
+ a = makeBinaryInterval(newBytesRef(), false, newBytesRef(zeros, 0, 2), true);
assertTrue(Operations.isFinite(a));
- assertFalse(accepts(a, new BytesRef()));
- assertTrue(accepts(a, new BytesRef(zeros, 0, 1)));
- assertTrue(accepts(a, new BytesRef(zeros, 0, 2)));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 3)));
+ assertFalse(accepts(a, newBytesRef()));
+ assertTrue(accepts(a, newBytesRef(zeros, 0, 1)));
+ assertTrue(accepts(a, newBytesRef(zeros, 0, 2)));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 3)));
// 0 (excl) - 00 (incl)
- a = makeBinaryInterval(new BytesRef(zeros, 0, 1), false, new BytesRef(zeros, 0, 2), true);
+ a = makeBinaryInterval(newBytesRef(zeros, 0, 1), false, newBytesRef(zeros, 0, 2), true);
assertTrue(Operations.isFinite(a));
- assertFalse(accepts(a, new BytesRef()));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 1)));
- assertTrue(accepts(a, new BytesRef(zeros, 0, 2)));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 3)));
+ assertFalse(accepts(a, newBytesRef()));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 1)));
+ assertTrue(accepts(a, newBytesRef(zeros, 0, 2)));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 3)));
// 0 (excl) - 00 (excl)
- a = makeBinaryInterval(new BytesRef(zeros, 0, 1), false, new BytesRef(zeros, 0, 2), false);
+ a = makeBinaryInterval(newBytesRef(zeros, 0, 1), false, newBytesRef(zeros, 0, 2), false);
assertTrue(Operations.isFinite(a));
- assertFalse(accepts(a, new BytesRef()));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 1)));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 2)));
- assertFalse(accepts(a, new BytesRef(zeros, 0, 3)));
+ assertFalse(accepts(a, newBytesRef()));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 1)));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 2)));
+ assertFalse(accepts(a, newBytesRef(zeros, 0, 3)));
}
public void testMakeBinaryIntervalFiniteCasesRandom() throws Exception {
int iters = atLeast(100);
for (int iter = 0; iter < iters; iter++) {
- BytesRef prefix = new BytesRef(TestUtil.randomRealisticUnicodeString(random()));
+ BytesRef prefix = newBytesRef(TestUtil.randomRealisticUnicodeString(random()));
BytesRefBuilder b = new BytesRefBuilder();
b.append(prefix);
@@ -1496,12 +1496,12 @@ public class TestAutomaton extends LuceneTestCase {
private static IntsRef intsRef(String s) {
IntsRefBuilder intsBuilder = new IntsRefBuilder();
- Util.toIntsRef(new BytesRef(s), intsBuilder);
+ Util.toIntsRef(newBytesRef(s), intsBuilder);
return intsBuilder.toIntsRef();
}
public void testMakeBinaryIntervalBasic() throws Exception {
- Automaton a = Automata.makeBinaryInterval(new BytesRef("bar"), true, new BytesRef("foo"), true);
+ Automaton a = Automata.makeBinaryInterval(newBytesRef("bar"), true, newBytesRef("foo"), true);
assertTrue(Operations.run(a, intsRef("bar")));
assertTrue(Operations.run(a, intsRef("foo")));
assertTrue(Operations.run(a, intsRef("beep")));
@@ -1510,14 +1510,14 @@ public class TestAutomaton extends LuceneTestCase {
}
public void testMakeBinaryIntervalLowerBoundEmptyString() throws Exception {
- Automaton a = Automata.makeBinaryInterval(new BytesRef(""), true, new BytesRef("bar"), true);
+ Automaton a = Automata.makeBinaryInterval(newBytesRef(""), true, newBytesRef("bar"), true);
assertTrue(Operations.run(a, intsRef("")));
assertTrue(Operations.run(a, intsRef("a")));
assertTrue(Operations.run(a, intsRef("bar")));
assertFalse(Operations.run(a, intsRef("bara")));
assertFalse(Operations.run(a, intsRef("baz")));
- a = Automata.makeBinaryInterval(new BytesRef(""), false, new BytesRef("bar"), true);
+ a = Automata.makeBinaryInterval(newBytesRef(""), false, newBytesRef("bar"), true);
assertFalse(Operations.run(a, intsRef("")));
assertTrue(Operations.run(a, intsRef("a")));
assertTrue(Operations.run(a, intsRef("bar")));
@@ -1526,7 +1526,7 @@ public class TestAutomaton extends LuceneTestCase {
}
public void testMakeBinaryIntervalEqual() throws Exception {
- Automaton a = Automata.makeBinaryInterval(new BytesRef("bar"), true, new BytesRef("bar"), true);
+ Automaton a = Automata.makeBinaryInterval(newBytesRef("bar"), true, newBytesRef("bar"), true);
assertTrue(Operations.run(a, intsRef("bar")));
assertTrue(Operations.isFinite(a));
assertEquals(1, TestOperations.getFiniteStrings(a).size());
@@ -1534,7 +1534,7 @@ public class TestAutomaton extends LuceneTestCase {
public void testMakeBinaryIntervalCommonPrefix() throws Exception {
Automaton a =
- Automata.makeBinaryInterval(new BytesRef("bar"), true, new BytesRef("barfoo"), true);
+ Automata.makeBinaryInterval(newBytesRef("bar"), true, newBytesRef("barfoo"), true);
assertFalse(Operations.run(a, intsRef("bam")));
assertTrue(Operations.run(a, intsRef("bar")));
assertTrue(Operations.run(a, intsRef("bara")));
@@ -1553,7 +1553,7 @@ public class TestAutomaton extends LuceneTestCase {
}
public void testMakeBinaryIntervalOpenMax() throws Exception {
- Automaton a = Automata.makeBinaryInterval(new BytesRef("bar"), true, null, true);
+ Automaton a = Automata.makeBinaryInterval(newBytesRef("bar"), true, null, true);
assertFalse(Operations.run(a, intsRef("bam")));
assertTrue(Operations.run(a, intsRef("bar")));
assertTrue(Operations.run(a, intsRef("bara")));
@@ -1568,19 +1568,19 @@ public class TestAutomaton extends LuceneTestCase {
public void testMakeBinaryIntervalOpenMaxZeroLengthMin() throws Exception {
// when including min, automaton should accept "a"
- Automaton a = Automata.makeBinaryInterval(new BytesRef(""), true, null, true);
+ Automaton a = Automata.makeBinaryInterval(newBytesRef(""), true, null, true);
assertTrue(Operations.run(a, intsRef("")));
assertTrue(Operations.run(a, intsRef("a")));
assertTrue(Operations.run(a, intsRef("aaaaaa")));
// excluding min should still accept "a"
- a = Automata.makeBinaryInterval(new BytesRef(""), false, null, true);
+ a = Automata.makeBinaryInterval(newBytesRef(""), false, null, true);
assertFalse(Operations.run(a, intsRef("")));
assertTrue(Operations.run(a, intsRef("a")));
assertTrue(Operations.run(a, intsRef("aaaaaa")));
}
public void testMakeBinaryIntervalOpenMin() throws Exception {
- Automaton a = Automata.makeBinaryInterval(null, true, new BytesRef("foo"), true);
+ Automaton a = Automata.makeBinaryInterval(null, true, newBytesRef("foo"), true);
assertFalse(Operations.run(a, intsRef("foz")));
assertFalse(Operations.run(a, intsRef("zzz")));
assertTrue(Operations.run(a, intsRef("foo")));
@@ -1602,7 +1602,7 @@ public class TestAutomaton extends LuceneTestCase {
}
public void testAcceptAllEmptyStringMin() throws Exception {
- Automaton a = Automata.makeBinaryInterval(new BytesRef(), true, null, true);
+ Automaton a = Automata.makeBinaryInterval(newBytesRef(), true, null, true);
assertTrue(Operations.sameLanguage(Automata.makeAnyBinary(), a));
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
index 02a6e9522ff..48308a56496 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
@@ -260,7 +260,7 @@ public class TestRegExp extends LuceneTestCase {
RegExp regex = new RegExp(regexPattern, RegExp.ALL, matchFlags);
Automaton automaton = regex.toAutomaton();
ByteRunAutomaton bytesMatcher = new ByteRunAutomaton(automaton);
- BytesRef br = new BytesRef(docValue);
+ BytesRef br = newBytesRef(docValue);
assertTrue(
"["
+ regexPattern
diff --git a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
index 58eeb2d4537..4773236080a 100644
--- a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
+++ b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
@@ -161,7 +161,7 @@ public class TestFSTs extends LuceneTestCase {
final ByteSequenceOutputs outputs = ByteSequenceOutputs.getSingleton();
final List<FSTTester.InputOutput<BytesRef>> pairs = new ArrayList<>(terms2.length);
for (int idx = 0; idx < terms2.length; idx++) {
- final BytesRef output = new BytesRef(Integer.toString(idx));
+ final BytesRef output = newBytesRef(Integer.toString(idx));
pairs.add(new FSTTester.InputOutput<>(terms2[idx], output));
}
FSTTester<BytesRef> tester = new FSTTester<>(random(), dir, inputMode, pairs, outputs);
@@ -245,7 +245,7 @@ public class TestFSTs extends LuceneTestCase {
final List<FSTTester.InputOutput<BytesRef>> pairs = new ArrayList<>(terms.length);
for (int idx = 0; idx < terms.length; idx++) {
final BytesRef output =
- random().nextInt(30) == 17 ? NO_OUTPUT : new BytesRef(Integer.toString(idx));
+ random().nextInt(30) == 17 ? NO_OUTPUT : newBytesRef(Integer.toString(idx));
pairs.add(new FSTTester.InputOutput<>(terms[idx], output));
}
new FSTTester<>(random(), dir, inputMode, pairs, outputs).doTest(true);
@@ -411,7 +411,7 @@ public class TestFSTs extends LuceneTestCase {
final BytesRefFSTEnum<Long> fstEnum = new BytesRefFSTEnum<>(fst);
int num = atLeast(1000);
for (int iter = 0; iter < num; iter++) {
- final BytesRef randomTerm = new BytesRef(getRandomString(random));
+ final BytesRef randomTerm = newBytesRef(getRandomString(random));
if (VERBOSE) {
System.out.println(
@@ -762,10 +762,10 @@ public class TestFSTs extends LuceneTestCase {
final Outputs<Object> outputs = NoOutputs.getSingleton();
final FSTCompiler<Object> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
fstCompiler.add(
- Util.toIntsRef(new BytesRef("foobar"), new IntsRefBuilder()), outputs.getNoOutput());
+ Util.toIntsRef(newBytesRef("foobar"), new IntsRefBuilder()), outputs.getNoOutput());
final BytesRefFSTEnum<Object> fstEnum = new BytesRefFSTEnum<>(fstCompiler.compile());
- assertNull(fstEnum.seekFloor(new BytesRef("foo")));
- assertNull(fstEnum.seekCeil(new BytesRef("foobaz")));
+ assertNull(fstEnum.seekFloor(newBytesRef("foo")));
+ assertNull(fstEnum.seekCeil(newBytesRef("foobaz")));
}
public void testDuplicateFSAString() throws Exception {
@@ -774,7 +774,7 @@ public class TestFSTs extends LuceneTestCase {
final FSTCompiler<Object> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
IntsRefBuilder ints = new IntsRefBuilder();
for (int i = 0; i < 10; i++) {
- fstCompiler.add(Util.toIntsRef(new BytesRef(str), ints), outputs.getNoOutput());
+ fstCompiler.add(Util.toIntsRef(newBytesRef(str), ints), outputs.getNoOutput());
}
FST<Object> fst = fstCompiler.compile();
@@ -786,8 +786,8 @@ public class TestFSTs extends LuceneTestCase {
}
assertEquals(1, count);
- assertNotNull(Util.get(fst, new BytesRef(str)));
- assertNull(Util.get(fst, new BytesRef("foobaz")));
+ assertNotNull(Util.get(fst, newBytesRef(str)));
+ assertNull(Util.get(fst, newBytesRef("foobaz")));
}
/*
@@ -813,7 +813,7 @@ public class TestFSTs extends LuceneTestCase {
Arrays.sort(strings);
final IntsRef scratch = new IntsRef();
for(String s : strings) {
- builder.add(Util.toIntsRef(new BytesRef(s), scratch), outputs.getNoOutput());
+ builder.add(Util.toIntsRef(newBytesRef(s), scratch), outputs.getNoOutput());
}
final FST<Object> fst = builder.finish();
System.out.println("DOT before rewrite");
@@ -842,9 +842,9 @@ public class TestFSTs extends LuceneTestCase {
// Build an FST mapping BytesRef -> Long
final FSTCompiler<Long> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
- final BytesRef a = new BytesRef("a");
- final BytesRef b = new BytesRef("b");
- final BytesRef c = new BytesRef("c");
+ final BytesRef a = newBytesRef("a");
+ final BytesRef b = newBytesRef("b");
+ final BytesRef c = newBytesRef("c");
fstCompiler.add(Util.toIntsRef(a, new IntsRefBuilder()), 17L);
fstCompiler.add(Util.toIntsRef(b, new IntsRefBuilder()), 42L);
@@ -863,12 +863,12 @@ public class TestFSTs extends LuceneTestCase {
assertEquals(17, (long) seekResult.output);
// goes to a
- seekResult = fstEnum.seekFloor(new BytesRef("aa"));
+ seekResult = fstEnum.seekFloor(newBytesRef("aa"));
assertNotNull(seekResult);
assertEquals(17, (long) seekResult.output);
// goes to b
- seekResult = fstEnum.seekCeil(new BytesRef("aa"));
+ seekResult = fstEnum.seekCeil(newBytesRef("aa"));
assertNotNull(seekResult);
assertEquals(b, seekResult.input);
assertEquals(42, (long) seekResult.output);
@@ -987,20 +987,20 @@ public class TestFSTs extends LuceneTestCase {
final TermsEnum.SeekStatus status;
if (nextID == null) {
- if (termsEnum.seekExact(new BytesRef(id))) {
+ if (termsEnum.seekExact(newBytesRef(id))) {
status = TermsEnum.SeekStatus.FOUND;
} else {
status = TermsEnum.SeekStatus.NOT_FOUND;
}
} else {
- status = termsEnum.seekCeil(new BytesRef(id));
+ status = termsEnum.seekCeil(newBytesRef(id));
}
if (nextID != null) {
assertEquals(TermsEnum.SeekStatus.NOT_FOUND, status);
assertEquals(
"expected=" + nextID + " actual=" + termsEnum.term().utf8ToString(),
- new BytesRef(nextID),
+ newBytesRef(nextID),
termsEnum.term());
} else if (!exists) {
assertEquals(TermsEnum.SeekStatus.NOT_FOUND, status);
@@ -1170,9 +1170,9 @@ public class TestFSTs extends LuceneTestCase {
final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
final FSTCompiler<Long> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
fstCompiler.add(
- Util.toIntsRef(new BytesRef("stat"), new IntsRefBuilder()), outputs.getNoOutput());
+ Util.toIntsRef(newBytesRef("stat"), new IntsRefBuilder()), outputs.getNoOutput());
fstCompiler.add(
- Util.toIntsRef(new BytesRef("station"), new IntsRefBuilder()), outputs.getNoOutput());
+ Util.toIntsRef(newBytesRef("station"), new IntsRefBuilder()), outputs.getNoOutput());
final FST<Long> fst = fstCompiler.compile();
StringWriter w = new StringWriter();
// Writer w = new OutputStreamWriter(new FileOutputStream("/x/tmp/out.dot"));
@@ -1269,9 +1269,9 @@ public class TestFSTs extends LuceneTestCase {
final FSTCompiler<Long> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
final IntsRefBuilder scratch = new IntsRefBuilder();
- fstCompiler.add(Util.toIntsRef(new BytesRef("aab"), scratch), 22L);
- fstCompiler.add(Util.toIntsRef(new BytesRef("aac"), scratch), 7L);
- fstCompiler.add(Util.toIntsRef(new BytesRef("ax"), scratch), 17L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("aab"), scratch), 22L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("aac"), scratch), 7L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("ax"), scratch), 17L);
final FST<Long> fst = fstCompiler.compile();
// Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"));
// Util.toDot(fst, w, false, false);
@@ -1287,13 +1287,13 @@ public class TestFSTs extends LuceneTestCase {
true);
assertTrue(res.isComplete);
assertEquals(3, res.topN.size());
- assertEquals(Util.toIntsRef(new BytesRef("aac"), scratch), res.topN.get(0).input);
+ assertEquals(Util.toIntsRef(newBytesRef("aac"), scratch), res.topN.get(0).input);
assertEquals(7L, res.topN.get(0).output.longValue());
- assertEquals(Util.toIntsRef(new BytesRef("ax"), scratch), res.topN.get(1).input);
+ assertEquals(Util.toIntsRef(newBytesRef("ax"), scratch), res.topN.get(1).input);
assertEquals(17L, res.topN.get(1).output.longValue());
- assertEquals(Util.toIntsRef(new BytesRef("aab"), scratch), res.topN.get(2).input);
+ assertEquals(Util.toIntsRef(newBytesRef("aab"), scratch), res.topN.get(2).input);
assertEquals(22L, res.topN.get(2).output.longValue());
}
@@ -1302,12 +1302,12 @@ public class TestFSTs extends LuceneTestCase {
final FSTCompiler<Long> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
final IntsRefBuilder scratch = new IntsRefBuilder();
- fstCompiler.add(Util.toIntsRef(new BytesRef("aab"), scratch), 22L);
- fstCompiler.add(Util.toIntsRef(new BytesRef("aac"), scratch), 7L);
- fstCompiler.add(Util.toIntsRef(new BytesRef("adcd"), scratch), 17L);
- fstCompiler.add(Util.toIntsRef(new BytesRef("adcde"), scratch), 17L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("aab"), scratch), 22L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("aac"), scratch), 7L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("adcd"), scratch), 17L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("adcde"), scratch), 17L);
- fstCompiler.add(Util.toIntsRef(new BytesRef("ax"), scratch), 17L);
+ fstCompiler.add(Util.toIntsRef(newBytesRef("ax"), scratch), 17L);
final FST<Long> fst = fstCompiler.compile();
final AtomicInteger rejectCount = new AtomicInteger();
Util.TopNSearcher<Long> searcher =
@@ -1329,7 +1329,7 @@ public class TestFSTs extends LuceneTestCase {
assertTrue(res.isComplete); // rejected(4) + topN(2) <= maxQueueSize(6)
assertEquals(1, res.topN.size());
- assertEquals(Util.toIntsRef(new BytesRef("aac"), scratch), res.topN.get(0).input);
+ assertEquals(Util.toIntsRef(newBytesRef("aac"), scratch), res.topN.get(0).input);
assertEquals(7L, res.topN.get(0).output.longValue());
rejectCount.set(0);
searcher =
@@ -1368,9 +1368,9 @@ public class TestFSTs extends LuceneTestCase {
new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
final IntsRefBuilder scratch = new IntsRefBuilder();
- fstCompiler.add(Util.toIntsRef(new BytesRef("aab"), scratch), outputs.newPair(22L, 57L));
- fstCompiler.add(Util.toIntsRef(new BytesRef("aac"), scratch), outputs.newPair(7L, 36L));
- fstCompiler.add(Util.toIntsRef(new BytesRef("ax"), scratch), outputs.newPair(17L, 85L));
+ fstCompiler.add(Util.toIntsRef(newBytesRef("aab"), scratch), outputs.newPair(22L, 57L));
+ fstCompiler.add(Util.toIntsRef(newBytesRef("aac"), scratch), outputs.newPair(7L, 36L));
+ fstCompiler.add(Util.toIntsRef(newBytesRef("ax"), scratch), outputs.newPair(17L, 85L));
final FST<Pair<Long, Long>> fst = fstCompiler.compile();
// Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"));
// Util.toDot(fst, w, false, false);
@@ -1387,15 +1387,15 @@ public class TestFSTs extends LuceneTestCase {
assertTrue(res.isComplete);
assertEquals(3, res.topN.size());
- assertEquals(Util.toIntsRef(new BytesRef("aac"), scratch), res.topN.get(0).input);
+ assertEquals(Util.toIntsRef(newBytesRef("aac"), scratch), res.topN.get(0).input);
assertEquals(7L, res.topN.get(0).output.output1.longValue()); // weight
assertEquals(36L, res.topN.get(0).output.output2.longValue()); // output
- assertEquals(Util.toIntsRef(new BytesRef("ax"), scratch), res.topN.get(1).input);
+ assertEquals(Util.toIntsRef(newBytesRef("ax"), scratch), res.topN.get(1).input);
assertEquals(17L, res.topN.get(1).output.output1.longValue()); // weight
assertEquals(85L, res.topN.get(1).output.output2.longValue()); // output
- assertEquals(Util.toIntsRef(new BytesRef("aab"), scratch), res.topN.get(2).input);
+ assertEquals(Util.toIntsRef(newBytesRef("aab"), scratch), res.topN.get(2).input);
assertEquals(22L, res.topN.get(2).output.output1.longValue()); // weight
assertEquals(57L, res.topN.get(2).output.output2.longValue()); // output
}
@@ -1426,7 +1426,7 @@ public class TestFSTs extends LuceneTestCase {
for (Map.Entry<String, Long> e : slowCompletor.entrySet()) {
// System.out.println("add: " + e);
- fstCompiler.add(Util.toIntsRef(new BytesRef(e.getKey()), scratch), e.getValue());
+ fstCompiler.add(Util.toIntsRef(newBytesRef(e.getKey()), scratch), e.getValue());
}
final FST<Long> fst = fstCompiler.compile();
@@ -1467,7 +1467,7 @@ public class TestFSTs extends LuceneTestCase {
matches.add(
new Result<>(
Util.toIntsRef(
- new BytesRef(e.getKey().substring(prefix.length())), new IntsRefBuilder()),
+ newBytesRef(e.getKey().substring(prefix.length())), new IntsRefBuilder()),
e.getValue() - prefixOutput));
}
}
@@ -1553,7 +1553,7 @@ public class TestFSTs extends LuceneTestCase {
long weight = e.getValue().a;
long output = e.getValue().b;
fstCompiler.add(
- Util.toIntsRef(new BytesRef(e.getKey()), scratch), outputs.newPair(weight, output));
+ Util.toIntsRef(newBytesRef(e.getKey()), scratch), outputs.newPair(weight, output));
}
final FST<Pair<Long, Long>> fst = fstCompiler.compile();
@@ -1594,7 +1594,7 @@ public class TestFSTs extends LuceneTestCase {
matches.add(
new Result<>(
Util.toIntsRef(
- new BytesRef(e.getKey().substring(prefix.length())), new IntsRefBuilder()),
+ newBytesRef(e.getKey().substring(prefix.length())), new IntsRefBuilder()),
outputs.newPair(
e.getValue().a - prefixOutput.output1,
e.getValue().b - prefixOutput.output2)));
@@ -1628,7 +1628,7 @@ public class TestFSTs extends LuceneTestCase {
for (int arc = 0; arc < 6; arc++) {
input.setIntAt(0, arc);
output.bytes[0] = (byte) arc;
- fstCompiler.add(input.get(), BytesRef.deepCopyOf(output));
+ fstCompiler.add(input.get(), newBytesRef(BytesRef.deepCopyOf(output)));
}
final FST<BytesRef> fst = fstCompiler.compile();
@@ -1650,12 +1650,12 @@ public class TestFSTs extends LuceneTestCase {
Set<BytesRef> terms = new HashSet<>();
for (int i = 0; i < 100; i++) {
String prefix = Character.toString((char) ('a' + i));
- terms.add(new BytesRef(prefix));
+ terms.add(newBytesRef(prefix));
if (prefix.equals("m") == false) {
for (int j = 0; j < 20; j++) {
// Make a big enough FST that the root cache will be created:
String suffix = TestUtil.randomRealisticUnicodeString(random(), 10, 20);
- terms.add(new BytesRef(prefix + suffix));
+ terms.add(newBytesRef(prefix + suffix));
}
}
}
@@ -1679,7 +1679,7 @@ public class TestFSTs extends LuceneTestCase {
FST.BytesReader reader = fst.getBytesReader();
arc = fst.findTargetArc('m', arc, arc, reader);
assertNotNull(arc);
- assertEquals(new BytesRef("m"), arc.output());
+ assertEquals(newBytesRef("m"), arc.output());
// NOTE: illegal:
arc.output().length = 0;
@@ -1698,9 +1698,9 @@ public class TestFSTs extends LuceneTestCase {
PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
FSTCompiler<Long> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
- BytesRef ab = new BytesRef("ab");
- BytesRef ac = new BytesRef("ac");
- BytesRef bd = new BytesRef("bd");
+ BytesRef ab = newBytesRef("ab");
+ BytesRef ac = newBytesRef("ac");
+ BytesRef bd = newBytesRef("bd");
fstCompiler.add(Util.toIntsRef(ab, new IntsRefBuilder()), 3L);
fstCompiler.add(Util.toIntsRef(ac, new IntsRefBuilder()), 5L);
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
index 8ce27c3e182..a402319acdc 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
@@ -3217,7 +3217,7 @@ public abstract class LuceneTestCase extends Assert {
*/
public static BytesRef newBytesRef(byte[] bytesIn, int offset, int length) {
// System.out.println("LTC.newBytesRef! bytesIn.length=" + bytesIn.length + " offset=" + offset
- // + " length=" + length);
+ // + " length=" + length);
assert bytesIn.length >= offset + length
: "got offset=" + offset + " length=" + length + " bytesIn.length=" + bytesIn.length;
@@ -3242,10 +3242,16 @@ public abstract class LuceneTestCase extends Assert {
System.arraycopy(bytesIn, offset, bytes, startOffset, length);
// System.out.println("LTC: return bytes.length=" + bytes.length + " startOffset=" +
- // startOffset + " length=" + bytesIn.length);
+ // startOffset + " length=" + length);
- BytesRef it = new BytesRef(bytes, startOffset, bytesIn.length);
+ BytesRef it = new BytesRef(bytes, startOffset, length);
assert it.isValid();
+
+ if (RandomNumbers.randomIntBetween(random(), 1, 17) == 7) {
+ // try to ferret out bugs in this method too!
+ return newBytesRef(it.bytes, it.offset, it.length);
+ }
+
return it;
}
}