Index: modules/analysis/icu/src/java/org/apache/lucene/collation/tokenattributes/ICUCollatedTermAttributeImpl.java =================================================================== --- modules/analysis/icu/src/java/org/apache/lucene/collation/tokenattributes/ICUCollatedTermAttributeImpl.java (revision 1075830) +++ modules/analysis/icu/src/java/org/apache/lucene/collation/tokenattributes/ICUCollatedTermAttributeImpl.java (working copy) @@ -42,7 +42,8 @@ @Override public int toBytesRef(BytesRef target) { collator.getRawCollationKey(toString(), key); - target.bytes = key.bytes; + target.grow(key.size); + System.arraycopy(key.bytes, 0, target.bytes, 0, key.size); target.offset = 0; target.length = key.size; return target.hashCode(); Index: lucene/src/test/org/apache/lucene/index/Test2BTerms.java =================================================================== --- lucene/src/test/org/apache/lucene/index/Test2BTerms.java (revision 1075520) +++ lucene/src/test/org/apache/lucene/index/Test2BTerms.java (working copy) @@ -75,9 +75,7 @@ private final static class MyTermAttributeImpl extends AttributeImpl implements TermToBytesRefAttribute { public int toBytesRef(BytesRef bs) { - bs.bytes = bytes.bytes; - bs.offset = bytes.offset; - bs.length = bytes.length; + bs.copy(bytes); return bytes.hashCode(); } @Override Index: lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java =================================================================== --- lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java (revision 1075520) +++ lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java (working copy) @@ -44,6 +44,8 @@ * Implement this for performance reasons, if your code can calculate * the hash on-the-fly. If this is not the case, just return * {@code termBytes.hashCode()}. + * NOTE: you must make a new copy of the underlying byte[] for each term, as + * the consumer owns this byte array. */ public int toBytesRef(BytesRef termBytes); }