From 6f92315865e9ab7472c565f7f289cbf8baa84a0e Mon Sep 17 00:00:00 2001 From: David Wayne Smiley Date: Tue, 13 May 2014 21:23:08 +0000 Subject: [PATCH] LUCENE-5608 fix assertions given that tokens are re-used git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1594391 13f79535-47bb-0310-9956-ffa450edef68 --- .../prefix/ContainsPrefixTreeFilter.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ContainsPrefixTreeFilter.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ContainsPrefixTreeFilter.java index 4bf903d4899..368b37526e8 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ContainsPrefixTreeFilter.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ContainsPrefixTreeFilter.java @@ -83,6 +83,7 @@ public class ContainsPrefixTreeFilter extends AbstractPrefixTreeFilter { super(context, acceptDocs); } + //The reused value of cell.getTokenBytesNoLeaf which is always then seek()'ed to. It's used in assertions too. BytesRef termBytes = new BytesRef();//no leaf Cell nextCell;//see getLeafDocs @@ -135,21 +136,24 @@ public class ContainsPrefixTreeFilter extends AbstractPrefixTreeFilter { if (termsEnum == null) return false; termBytes = cell.getTokenBytesNoLeaf(termBytes); + assert assertCloneTermBytes(); //assertions look at termBytes later on return termsEnum.seekExact(termBytes); } + private boolean assertCloneTermBytes() { + termBytes = BytesRef.deepCopyOf(termBytes); + return true; + } + private SmallDocSet getDocs(Cell cell, Bits acceptContains) throws IOException { assert cell.getTokenBytesNoLeaf(null).equals(termBytes); return collectDocs(acceptContains); } - private Cell lastLeaf = null;//just for assertion - - private SmallDocSet getLeafDocs(Cell leafCell, Bits acceptContains) throws IOException { - assert leafCell.getTokenBytesNoLeaf(null).equals(termBytes); - assert ! leafCell.equals(lastLeaf);//don't call for same leaf again - lastLeaf = leafCell; + /** Gets docs on the leaf of the given cell, _if_ there is a leaf cell, otherwise null. */ + private SmallDocSet getLeafDocs(Cell cell, Bits acceptContains) throws IOException { + assert cell.getTokenBytesNoLeaf(null).equals(termBytes); if (termsEnum == null) return null; @@ -159,8 +163,8 @@ public class ContainsPrefixTreeFilter extends AbstractPrefixTreeFilter { return null; } nextCell = grid.readCell(nextTerm, nextCell); - assert leafCell.isPrefixOf(nextCell); - if (nextCell.getLevel() == leafCell.getLevel() && nextCell.isLeaf()) { + assert cell.isPrefixOf(nextCell); + if (nextCell.getLevel() == cell.getLevel() && nextCell.isLeaf()) { return collectDocs(acceptContains); } else { return null;