lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r917204 - /lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
Date Sun, 28 Feb 2010 17:00:14 GMT
Author: mikemccand
Date: Sun Feb 28 17:00:14 2010
New Revision: 917204

URL: http://svn.apache.org/viewvc?rev=917204&view=rev
Log:
LUCENE-2289: check infoStream != null before calling message

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

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=917204&r1=917203&r2=917204&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Sun Feb 28 17:00:14
2010
@@ -493,10 +493,14 @@
     return infoStream;
   }
 
+  /**
+   * Prints the given message to the infoStream. Note, this method does not
+   * check for null infoStream. It assumes this check has been performed by the
+   * caller, which is recommended to avoid the (usually) expensive message
+   * creation.
+   */
   private static void message(String message) {
-    if (infoStream != null) {
-      infoStream.println("SIS [" + Thread.currentThread().getName() + "]: " + message);
-    }
+    infoStream.println("SIS [" + Thread.currentThread().getName() + "]: " + message);
   }
 
   /**
@@ -569,7 +573,9 @@
           if (files != null)
             genA = getCurrentSegmentGeneration(files);
 
-          message("directory listing genA=" + genA);
+          if (infoStream != null) {
+            message("directory listing genA=" + genA);
+          }
 
           // Method 2: open segments.gen and read its
           // contents.  Then we take the larger of the two
@@ -582,10 +588,14 @@
             try {
               genInput = directory.openInput(IndexFileNames.SEGMENTS_GEN);
             } catch (FileNotFoundException e) {
-              message("segments.gen open: FileNotFoundException " + e);
+              if (infoStream != null) {
+                message("segments.gen open: FileNotFoundException " + e);
+              }
               break;
             } catch (IOException e) {
-              message("segments.gen open: IOException " + e);
+              if (infoStream != null) {
+                message("segments.gen open: IOException " + e);
+              }
             }
   
             if (genInput != null) {
@@ -594,7 +604,9 @@
                 if (version == FORMAT_LOCKLESS) {
                   long gen0 = genInput.readLong();
                   long gen1 = genInput.readLong();
-                  message("fallback check: " + gen0 + "; " + gen1);
+                  if (infoStream != null) {
+                    message("fallback check: " + gen0 + "; " + gen1);
+                  }
                   if (gen0 == gen1) {
                     // The file is consistent.
                     genB = gen0;
@@ -614,7 +626,9 @@
             }
           }
 
-          message(IndexFileNames.SEGMENTS_GEN + " check: genB=" + genB);
+          if (infoStream != null) {
+            message(IndexFileNames.SEGMENTS_GEN + " check: genB=" + genB);
+          }
 
           // Pick the larger of the two gen's:
           if (genA > genB)
@@ -639,7 +653,9 @@
           if (genLookaheadCount < defaultGenLookaheadCount) {
             gen++;
             genLookaheadCount++;
-            message("look ahead increment gen to " + gen);
+            if (infoStream != null) {
+              message("look ahead increment gen to " + gen);
+            }
           }
         }
 
@@ -674,7 +690,7 @@
 
         try {
           Object v = doBody(segmentFileName);
-          if (exc != null) {
+          if (exc != null && infoStream != null) {
             message("success on " + segmentFileName);
           }
           return v;
@@ -685,7 +701,9 @@
             exc = err;
           }
 
-          message("primary Exception on '" + segmentFileName + "': " + err + "'; will retry:
retry=" + retry + "; gen = " + gen);
+          if (infoStream != null) {
+            message("primary Exception on '" + segmentFileName + "': " + err + "'; will retry:
retry=" + retry + "; gen = " + gen);
+          }
 
           if (!retry && gen > 1) {
 
@@ -702,13 +720,19 @@
             prevExists = directory.fileExists(prevSegmentFileName);
 
             if (prevExists) {
-              message("fallback to prior segment file '" + prevSegmentFileName + "'");
+              if (infoStream != null) {
+                message("fallback to prior segment file '" + prevSegmentFileName + "'");
+              }
               try {
                 Object v = doBody(prevSegmentFileName);
-                message("success on fallback " + prevSegmentFileName);
+                if (infoStream != null) {
+                  message("success on fallback " + prevSegmentFileName);
+                }
                 return v;
               } catch (IOException err2) {
-                message("secondary Exception on '" + prevSegmentFileName + "': " + err2 +
"'; will retry");
+                if (infoStream != null) {
+                  message("secondary Exception on '" + prevSegmentFileName + "': " + err2
+ "'; will retry");
+                }
               }
             }
           }



Mime
View raw message