lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r650984 - /lucene/java/trunk/src/java/org/apache/lucene/index/CheckIndex.java
Date Wed, 23 Apr 2008 18:26:07 GMT
Author: mikemccand
Date: Wed Apr 23 11:26:07 2008
New Revision: 650984

URL: http://svn.apache.org/viewvc?rev=650984&view=rev
Log:
LUCENE-1255: in CheckIndex, accept pos=-1 if index is < 2.4; added NOTE to remind user
to turn on assertions for more thorough checking

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/CheckIndex.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/CheckIndex.java?rev=650984&r1=650983&r2=650984&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/CheckIndex.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/CheckIndex.java Wed Apr 23 11:26:07
2008
@@ -104,6 +104,7 @@
 
     String sFormat = "";
     boolean skip = false;
+    boolean allowMinusOnePosition = true;
 
     if (format == SegmentInfos.FORMAT)
       sFormat = "FORMAT [Lucene Pre-2.1]";
@@ -113,13 +114,19 @@
       sFormat = "FORMAT_SINGLE_NORM_FILE [Lucene 2.2]";
     else if (format == SegmentInfos.FORMAT_SHARED_DOC_STORE)
       sFormat = "FORMAT_SHARED_DOC_STORE [Lucene 2.3]";
-    else if (format == SegmentInfos.FORMAT_CHECKSUM) {
-      sFormat = "FORMAT_CHECKSUM [Lucene 2.4]";
-    } else if (format < SegmentInfos.FORMAT_CHECKSUM) {
-      sFormat = "int=" + format + " [newer version of Lucene than this tool]";
-      skip = true;
-    } else {
-      sFormat = format + " [Lucene 1.3 or prior]";
+    else {
+      // LUCENE-1255: All versions before 2.3.2/2.4 were
+      // able to create position=-1 when the very first
+      // Token has positionIncrement 0
+      allowMinusOnePosition = false;
+      if (format == SegmentInfos.FORMAT_CHECKSUM) {
+        sFormat = "FORMAT_CHECKSUM [Lucene 2.4]";
+      } else if (format < SegmentInfos.FORMAT_CHECKSUM) {
+        sFormat = "int=" + format + " [newer version of Lucene than this tool]";
+        skip = true;
+      } else {
+        sFormat = format + " [Lucene 1.3 or prior]";
+      }
     }
 
     out.println("Segments file=" + segmentsFileName + " numSegments=" + numSegments + " version="
+ sFormat);
@@ -221,7 +228,7 @@
             totPos += freq;
             for(int j=0;j<freq;j++) {
               final int pos = termPositions.nextPosition();
-              if (pos < 0)
+              if (pos < -1 || (pos == -1 && !allowMinusOnePosition))
                 throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos
+ " is out of bounds");
               if (pos < lastPos)
                 throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos
+ " < lastPos " + lastPos);
@@ -338,6 +345,13 @@
     return false;
   }
 
+  static boolean assertsOn;
+
+  private static boolean testAsserts() {
+    assertsOn = true;
+    return true;
+  }
+
   public static void main(String[] args) throws Throwable {
 
     boolean doFix = false;
@@ -396,6 +410,10 @@
       out.println("ERROR: cannot specify both -fix and -segment");
       System.exit(1);
     }
+
+    assert testAsserts();
+    if (!assertsOn)
+      out.println("\nNOTE: testing will be more thorough if you run java with '-ea:org.apache.lucene',
so assertions are enabled");
 
     out.println("\nOpening index @ " + indexPath + "\n");
     Directory dir = null;



Mime
View raw message