LUCENE-4942: Fix BytesRefIteratorTokenStream's attribute clone method.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1665949 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2015-03-11 17:46:59 +00:00
parent 5a0e0e007a
commit 9cf30e5ed2
2 changed files with 12 additions and 2 deletions

View File

@ -87,7 +87,9 @@ class BytesRefIteratorTokenStream extends TokenStream {
@Override @Override
public BRTermToBytesRefAttributeImpl clone() { public BRTermToBytesRefAttributeImpl clone() {
final BRTermToBytesRefAttributeImpl clone = (BRTermToBytesRefAttributeImpl) super.clone(); // super.clone won't work since we need a new BytesRef reference and it's nice to have it final. The superclass
// has no state to copy anyway.
final BRTermToBytesRefAttributeImpl clone = new BRTermToBytesRefAttributeImpl();
clone.setBytesRef(BytesRef.deepCopyOf(bytes)); clone.setBytesRef(BytesRef.deepCopyOf(bytes));
return clone; return clone;
} }

View File

@ -31,6 +31,8 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -423,6 +425,12 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestB
((NamedList)result.get("field_types").get("location_rpt")).get("index"); ((NamedList)result.get("field_types").get("location_rpt")).get("index");
List<NamedList> tokenList = tokens.get("org.apache.lucene.spatial.prefix.BytesRefIteratorTokenStream"); List<NamedList> tokenList = tokens.get("org.apache.lucene.spatial.prefix.BytesRefIteratorTokenStream");
assertTrue( tokenList.get(0).get("text").toString().startsWith("s") );
List<String> vals = new ArrayList<>(tokenList.size());
for(NamedList v : tokenList) {
vals.add( (String)v.get("text") );
}
Collections.sort(vals);
assertEquals( "[s, s7, s7w, s7w1+, s9, s9v, s9v2+, sp, spp, spp5+, sv, svk, svk6+]", vals.toString() );
} }
} }