LUCENE-3079: fix MemoryCodec to always set BytesRef.bytes when returning payload

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1141218 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-06-29 19:46:14 +00:00
parent 2b8ef42a5c
commit 4401ef4dae
6 changed files with 21 additions and 4 deletions

View File

@ -471,7 +471,7 @@ public class MemoryCodec extends Codec {
@Override
public int nextPosition() {
if (VERBOSE) System.out.println(" nextPos storePayloads=" + storePayloads);
if (VERBOSE) System.out.println(" nextPos storePayloads=" + storePayloads + " this=" + this);
assert posPending > 0;
posPending--;
if (!storePayloads) {
@ -488,6 +488,9 @@ public class MemoryCodec extends Codec {
payload.offset = in.getPosition();
in.skipBytes(payloadLength);
payload.length = payloadLength;
// Necessary, in case caller changed the
// payload.bytes from prior call:
payload.bytes = buffer;
payloadRetrieved = false;
}

View File

@ -59,6 +59,7 @@ public final class ByteArrayDataInput extends DataInput {
public void skipBytes(int count) {
pos += count;
assert pos <= limit;
}
@Override

View File

@ -20,7 +20,8 @@ package org.apache.lucene.util;
import java.util.Comparator;
/** Represents byte[], as a slice (offset + length) into an
* existing byte[].
* existing byte[]. The {@link #bytes} member should never be null;
* use {@link #EMPTY_BYTES} if necessary.
*
* @lucene.experimental */
public final class BytesRef implements Comparable<BytesRef> {

View File

@ -19,7 +19,8 @@ package org.apache.lucene.util;
/**
* Represents char[], as a slice (offset + length) into an existing char[].
*
* The {@link #chars} member should never be null; use
* {@link #EMPTY_ARRAY} if necessary.
* @lucene.internal
*/
public final class CharsRef implements Comparable<CharsRef>, CharSequence {

View File

@ -18,11 +18,14 @@ package org.apache.lucene.util;
*/
/** Represents int[], as a slice (offset + length) into an
* existing int[].
* existing int[]. The {@link #ints} member should never be null; use
* {@link #EMPTY_INTS} if necessary.
*
* @lucene.internal */
public final class IntsRef implements Comparable<IntsRef> {
public static final int[] EMPTY_INTS = new int[0];
public int[] ints;
public int offset;
public int length;

View File

@ -241,6 +241,14 @@ public class TestPayloads extends LuceneTestCase {
BytesRef br = tps[j].getPayload();
System.arraycopy(br.bytes, br.offset, verifyPayloadData, offset, br.length);
offset += br.length;
// Just to ensure all codecs can
// handle a caller that mucks with the
// returned payload:
if (rarely()) {
br.bytes = new byte[random.nextInt(5)];
}
br.length = 0;
br.offset = 0;
}
}
}