You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/04/10 16:09:15 UTC
svn commit: r1311734 -
/lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java
Author: rmuir
Date: Tue Apr 10 14:09:15 2012
New Revision: 1311734
URL: http://svn.apache.org/viewvc?rev=1311734&view=rev
Log:
LUCENE-3969: check offsets even if posIncrAtt doesnt yet exist (and vice versa), and check that offsets are non-negative
Modified:
lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java
Modified: lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java?rev=1311734&r1=1311733&r2=1311734&view=diff
==============================================================================
--- lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java (original)
+++ lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java Tue Apr 10 14:09:15 2012
@@ -72,21 +72,35 @@ public final class ValidatingTokenFilter
return false;
}
- if (posIncAtt != null && offsetAtt != null) {
-
+ int startOffset = 0;
+ int endOffset = 0;
+ int posLen = 0;
+
+ if (posIncAtt != null) {
pos += posIncAtt.getPositionIncrement();
if (pos == -1) {
throw new IllegalStateException("first posInc must be > 0");
}
+ }
+
+ if (offsetAtt != null) {
+ startOffset = offsetAtt.startOffset();
+ endOffset = offsetAtt.endOffset();
- final int startOffset = offsetAtt.startOffset();
- final int endOffset = offsetAtt.endOffset();
-
+ if (startOffset < 0) {
+ throw new IllegalStateException(name + ": startOffset=" + startOffset + " is < 0");
+ }
+ if (endOffset < 0) {
+ throw new IllegalStateException(name + ": endOffset=" + endOffset + " is < 0");
+ }
if (endOffset < startOffset) {
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)) {
// First time we've seen a token leaving from this position: