lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r405852 - /lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
Date Fri, 12 May 2006 20:13:00 GMT
Author: dnaber
Date: Fri May 12 13:12:59 2006
New Revision: 405852

URL: http://svn.apache.org/viewcvs?rev=405852&view=rev
Log:
improve the exception messages and init the cause

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=405852&r1=405851&r2=405852&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Fri May 12 13:12:59
2006
@@ -80,12 +80,12 @@
                            FSDirectory.class.getName());
       IMPL = Class.forName(name);
     } catch (ClassNotFoundException e) {
-      throw new RuntimeException("cannot load FSDirectory class: " + e.toString());
+      throw new RuntimeException("cannot load FSDirectory class: " + e.toString(), e);
     } catch (SecurityException se) {
       try {
         IMPL = Class.forName(FSDirectory.class.getName());
       } catch (ClassNotFoundException e) {
-        throw new RuntimeException("cannot load default FSDirectory class: " + e.toString());
+        throw new RuntimeException("cannot load default FSDirectory class: " + e.toString(),
e);
       }
     }
   }
@@ -96,7 +96,7 @@
     try {
       DIGESTER = MessageDigest.getInstance("MD5");
     } catch (NoSuchAlgorithmException e) {
-        throw new RuntimeException(e.toString());
+        throw new RuntimeException(e.toString(), e);
     }
   }
 
@@ -136,7 +136,7 @@
         try {
           dir = (FSDirectory)IMPL.newInstance();
         } catch (Exception e) {
-          throw new RuntimeException("cannot load FSDirectory class: " + e.toString());
+          throw new RuntimeException("cannot load FSDirectory class: " + e.toString(), e);
         }
         dir.init(file, create);
         DIRECTORIES.put(file, dir);
@@ -168,9 +168,10 @@
     // Ensure that lockDir exists and is a directory.
     if (!lockDir.exists()) {
       if (!lockDir.mkdirs())
-        throw new IOException("Cannot create directory: " + lockDir);
+        throw new IOException("Cannot create directory: " + lockDir.getAbsolutePath());
     } else if (!lockDir.isDirectory()) {
-      throw new IOException("Found regular file where directory expected: " + lockDir);
+      throw new IOException("Found regular file where directory expected: " + 
+          lockDir.getAbsolutePath());
     }
     if (create) {
       create();
@@ -189,10 +190,12 @@
       throw new IOException(directory + " not a directory");
 
     String[] files = directory.list(new IndexFileNameFilter());            // clear old files
+    if (files == null)
+      throw new IOException("Cannot read directory " + directory.getAbsolutePath());
     for (int i = 0; i < files.length; i++) {
       File file = new File(directory, files[i]);
       if (!file.delete())
-        throw new IOException("Cannot delete " + files[i]);
+        throw new IOException("Cannot delete " + file);
     }
 
     String lockPrefix = getLockPrefix().toString(); // clear old locks
@@ -204,7 +207,7 @@
         continue;
       File lockFile = new File(lockDir, files[i]);
       if (!lockFile.delete())
-        throw new IOException("Cannot delete " + files[i]);
+        throw new IOException("Cannot delete " + lockFile);
     }
   }
 
@@ -288,21 +291,23 @@
         old.delete();
       }
       catch (IOException ioe) {
-        throw new IOException("Cannot rename " + old + " to " + nu);
+        IOException newExc = new IOException("Cannot rename " + old + " to " + nu);
+        newExc.initCause(ioe);
+        throw newExc;
       }
       finally {
         if (in != null) {
           try {
             in.close();
           } catch (IOException e) {
-            throw new RuntimeException("Cannot close input stream: " + e.toString());
+            throw new RuntimeException("Cannot close input stream: " + e.toString(), e);
           }
         }
         if (out != null) {
           try {
             out.close();
           } catch (IOException e) {
-            throw new RuntimeException("Cannot close output stream: " + e.toString());
+            throw new RuntimeException("Cannot close output stream: " + e.toString(), e);
           }
         }
       }
@@ -379,7 +384,7 @@
     try {
       dirName = directory.getCanonicalPath();
     } catch (IOException e) {
-      throw new RuntimeException(e.toString());
+      throw new RuntimeException(e.toString(), e);
     }
 
     byte digest[];



Mime
View raw message