improve the exception messages and init the cause

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@405852 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2006-05-12 20:12:59 +00:00
parent 67f3d7f262
commit cb5f472525

View File

@ -80,12 +80,12 @@ public class FSDirectory extends Directory {
FSDirectory.class.getName()); FSDirectory.class.getName());
IMPL = Class.forName(name); IMPL = Class.forName(name);
} catch (ClassNotFoundException e) { } 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) { } catch (SecurityException se) {
try { try {
IMPL = Class.forName(FSDirectory.class.getName()); IMPL = Class.forName(FSDirectory.class.getName());
} catch (ClassNotFoundException e) { } 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 @@ public class FSDirectory extends Directory {
try { try {
DIGESTER = MessageDigest.getInstance("MD5"); DIGESTER = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.toString()); throw new RuntimeException(e.toString(), e);
} }
} }
@ -136,7 +136,7 @@ public class FSDirectory extends Directory {
try { try {
dir = (FSDirectory)IMPL.newInstance(); dir = (FSDirectory)IMPL.newInstance();
} catch (Exception e) { } 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); dir.init(file, create);
DIRECTORIES.put(file, dir); DIRECTORIES.put(file, dir);
@ -168,9 +168,10 @@ public class FSDirectory extends Directory {
// Ensure that lockDir exists and is a directory. // Ensure that lockDir exists and is a directory.
if (!lockDir.exists()) { if (!lockDir.exists()) {
if (!lockDir.mkdirs()) if (!lockDir.mkdirs())
throw new IOException("Cannot create directory: " + lockDir); throw new IOException("Cannot create directory: " + lockDir.getAbsolutePath());
} else if (!lockDir.isDirectory()) { } 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) { if (create) {
create(); create();
@ -189,10 +190,12 @@ public class FSDirectory extends Directory {
throw new IOException(directory + " not a directory"); throw new IOException(directory + " not a directory");
String[] files = directory.list(new IndexFileNameFilter()); // clear old files 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++) { for (int i = 0; i < files.length; i++) {
File file = new File(directory, files[i]); File file = new File(directory, files[i]);
if (!file.delete()) if (!file.delete())
throw new IOException("Cannot delete " + files[i]); throw new IOException("Cannot delete " + file);
} }
String lockPrefix = getLockPrefix().toString(); // clear old locks String lockPrefix = getLockPrefix().toString(); // clear old locks
@ -204,7 +207,7 @@ public class FSDirectory extends Directory {
continue; continue;
File lockFile = new File(lockDir, files[i]); File lockFile = new File(lockDir, files[i]);
if (!lockFile.delete()) if (!lockFile.delete())
throw new IOException("Cannot delete " + files[i]); throw new IOException("Cannot delete " + lockFile);
} }
} }
@ -288,21 +291,23 @@ public class FSDirectory extends Directory {
old.delete(); old.delete();
} }
catch (IOException ioe) { 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 { finally {
if (in != null) { if (in != null) {
try { try {
in.close(); in.close();
} catch (IOException e) { } 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) { if (out != null) {
try { try {
out.close(); out.close();
} catch (IOException e) { } 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 @@ public class FSDirectory extends Directory {
try { try {
dirName = directory.getCanonicalPath(); dirName = directory.getCanonicalPath();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e.toString()); throw new RuntimeException(e.toString(), e);
} }
byte digest[]; byte digest[];