Index: solr/src/webapp/web/admin/analysis.jsp =================================================================== --- solr/src/webapp/web/admin/analysis.jsp (revision 1075520) +++ solr/src/webapp/web/admin/analysis.jsp (working copy) @@ -156,10 +156,10 @@ TermToBytesRefAttribute bytesAtt = tstream.getAttribute(TermToBytesRefAttribute.class); tstream.reset(); matches = new HashSet(); + final BytesRef spare = new BytesRef(); while (tstream.incrementToken()) { - final BytesRef bytes = new BytesRef(); - bytesAtt.toBytesRef(bytes); - matches.add(bytes); + bytesAtt.toBytesRef(spare); + matches.add(new BytesRef(spare)); } } Index: lucene/src/java/org/apache/lucene/queryParser/QueryParserBase.java =================================================================== --- lucene/src/java/org/apache/lucene/queryParser/QueryParserBase.java (revision 1075520) +++ lucene/src/java/org/apache/lucene/queryParser/QueryParserBase.java (working copy) @@ -532,18 +532,19 @@ // ignore } + BytesRef spare = new BytesRef(); + if (numTokens == 0) return null; else if (numTokens == 1) { - BytesRef term = new BytesRef(); try { boolean hasNext = buffer.incrementToken(); assert hasNext == true; - termAtt.toBytesRef(term); + termAtt.toBytesRef(spare); } catch (IOException e) { // safe to ignore, because we know the number of tokens } - return newTermQuery(new Term(field, term)); + return newTermQuery(new Term(field, new BytesRef(spare))); } else { if (severalTokensAtSamePosition || (!quoted && !autoGeneratePhraseQueries)) { if (positionCount == 1 || (!quoted && !autoGeneratePhraseQueries)) { @@ -554,17 +555,15 @@ BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD; for (int i = 0; i < numTokens; i++) { - BytesRef term = new BytesRef(); try { boolean hasNext = buffer.incrementToken(); assert hasNext == true; - termAtt.toBytesRef(term); + termAtt.toBytesRef(spare); } catch (IOException e) { // safe to ignore, because we know the number of tokens } - Query currentQuery = newTermQuery( - new Term(field, term)); + new Term(field, new BytesRef(spare))); q.add(currentQuery, occur); } return q; @@ -576,12 +575,11 @@ List multiTerms = new ArrayList(); int position = -1; for (int i = 0; i < numTokens; i++) { - BytesRef term = new BytesRef(); int positionIncrement = 1; try { boolean hasNext = buffer.incrementToken(); assert hasNext == true; - termAtt.toBytesRef(term); + termAtt.toBytesRef(spare); if (posIncrAtt != null) { positionIncrement = posIncrAtt.getPositionIncrement(); } @@ -598,7 +596,7 @@ multiTerms.clear(); } position += positionIncrement; - multiTerms.add(new Term(field, term)); + multiTerms.add(new Term(field, new BytesRef(spare))); } if (enablePositionIncrements) { mpq.add(multiTerms.toArray(new Term[0]),position); @@ -631,9 +629,9 @@ if (enablePositionIncrements) { position += positionIncrement; - pq.add(new Term(field, term),position); + pq.add(new Term(field, new BytesRef(term)),position); } else { - pq.add(new Term(field, term)); + pq.add(new Term(field, new BytesRef(term))); } } return pq; @@ -812,8 +810,9 @@ try { source.close(); } catch (IOException ignored) {} - - return result; + + // make a copy of the bytes, we might not "own" them and TermRangeQuery doesn't copy. + return new BytesRef(result); } /**