From d4b5405533cc89c12d9c72eaa924e2acf1a1ec07 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 10 Apr 2012 14:09:15 +0000 Subject: [PATCH] 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 --- .../analysis/ValidatingTokenFilter.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java index 984f8b5b696..9f81f7266cc 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java +++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java @@ -72,21 +72,35 @@ public final class ValidatingTokenFilter extends TokenFilter { 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: