Skip to content

Apache Lucene open-source search software

SOLR-2142: fix PagedBytes for copying zero-len BytesRef

Yonik Seeleyaa33fe16a639
diff --git a/lucene/src/java/org/apache/lucene/util/PagedBytes.java b/lucene/src/java/org/apache/lucene/util/PagedBytes.java
index 10471a2fe0e..9d42cdd94f7 100644
--- a/lucene/src/java/org/apache/lucene/util/PagedBytes.java
+++ b/lucene/src/java/org/apache/lucene/util/PagedBytes.java
@@ -228,7 +228,7 @@ public final class PagedBytes {
* This only supports bytes.length <= blockSize */
public void copy(BytesRef bytes, BytesRef out) throws IOException {
int left = blockSize - upto;
- if (bytes.length > left) {
+ if (bytes.length > left || currentBlock==null) {
if (currentBlock != null) {
blocks.add(currentBlock);
blockEnd.add(upto);
diff --git a/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java b/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java
index 64df20df1df..b66321ff9d6 100644
--- a/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java
+++ b/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java
@@ -94,7 +94,8 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
add_doc("id", "47",
"range_facet_f", "28.62",
"trait_s", "Pig",
- "text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!");
+ "text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!",
+ "zerolen_s","");
}
@Test
@@ -300,6 +301,16 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
,"//int[2][@name='Obnoxious'][.='1']"
,"//int[3][@name='Tool'][.='2']"
);
+
+
+ assertQ(req("q", "id:[42 TO 47]"
+ ,"facet", "true"
+ ,"facet.method","fc"
+ ,"fq", "id:[42 TO 45]"
+ ,"facet.field", "zerolen_s"
+ )
+ ,"*[count(//lst[@name='zerolen_s']/int)=1]"
+ );
}
public static void indexDateFacets() {