LUCENE-3969: check offsets even if posIncrAtt doesnt yet exist (and vice versa), and check that offsets are non-negative

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3969@1311734 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-04-10 14:09:15 +00:00
parent 3706fbc5b0
commit d4b5405533
1 changed files with 21 additions and 7 deletions

View File

@ -72,21 +72,35 @@ public final class ValidatingTokenFilter extends TokenFilter {
return false; return false;
} }
if (posIncAtt != null && offsetAtt != null) { int startOffset = 0;
int endOffset = 0;
int posLen = 0;
if (posIncAtt != null) {
pos += posIncAtt.getPositionIncrement(); pos += posIncAtt.getPositionIncrement();
if (pos == -1) { if (pos == -1) {
throw new IllegalStateException("first posInc must be > 0"); throw new IllegalStateException("first posInc must be > 0");
} }
}
if (offsetAtt != null) {
startOffset = offsetAtt.startOffset();
endOffset = offsetAtt.endOffset();
final int startOffset = offsetAtt.startOffset(); if (startOffset < 0) {
final int endOffset = offsetAtt.endOffset(); throw new IllegalStateException(name + ": startOffset=" + startOffset + " is < 0");
}
if (endOffset < 0) {
throw new IllegalStateException(name + ": endOffset=" + endOffset + " is < 0");
}
if (endOffset < startOffset) { if (endOffset < startOffset) {
throw new IllegalStateException(name + ": startOffset=" + startOffset + " is > endOffset=" + endOffset + " pos=" + pos + "; token=" + termAtt); throw new IllegalStateException(name + ": startOffset=" + startOffset + " is > endOffset=" + endOffset + " pos=" + pos + "; token=" + termAtt);
} }
}
final int posLen = posLenAtt == null ? 1 : posLenAtt.getPositionLength();
posLen = posLenAtt == null ? 1 : posLenAtt.getPositionLength();
if (offsetAtt != null && posIncAtt != null) {
if (!posToStartOffset.containsKey(pos)) { if (!posToStartOffset.containsKey(pos)) {
// First time we've seen a token leaving from this position: // First time we've seen a token leaving from this position: