Index: src/java/org/apache/nutch/indexer/IndexMerger.java
===================================================================
--- src/java/org/apache/nutch/indexer/IndexMerger.java	(revision 551587)
+++ src/java/org/apache/nutch/indexer/IndexMerger.java	(working copy)
@@ -24,6 +24,7 @@
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.hadoop.fs.*;
+import org.apache.hadoop.mapred.FileAlreadyExistsException;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.ToolBase;
 import org.apache.hadoop.conf.*;
@@ -57,22 +58,25 @@
   /**
    * Merge all input indexes to the single output index
    */
-  public void merge(Path[] indexes, Path outputIndex, Path localWorkingDir) throws IOException {
+  public void merge(Path[] indexes, Path outputIndex, Path localWorkingDir) 
+  	throws IOException {
     if (LOG.isInfoEnabled()) {
       LOG.info("merging indexes to: " + outputIndex);
     }
     FileSystem localFs = FileSystem.getLocal(getConf());
-    if (localWorkingDir == null) {
-      localWorkingDir = new Path("indexmerger-" + System.currentTimeMillis());
-    }
+    
     if (localFs.exists(localWorkingDir)) {
       localFs.delete(localWorkingDir);
     }
     localFs.mkdirs(localWorkingDir);
-
+    
     // Get local output target
     //
     FileSystem fs = FileSystem.get(getConf());
+    if (fs.exists(outputIndex)) {
+      throw new FileAlreadyExistsException("Output directory " + outputIndex + " already exists!");
+    }
+
     Path tmpLocalOutput = new Path(localWorkingDir, "merge-output");
     Path localOutput = fs.startLocalOutput(outputIndex, tmpLocalOutput);
 
@@ -82,9 +86,8 @@
       dirs[i] = new FsDirectory(fs, indexes[i], false, this.conf);
     }
 
+    
     //
-
-    //
     // Merge indices
     //
     IndexWriter writer = new IndexWriter(localOutput.toString(), null, true);
@@ -102,7 +105,6 @@
     // Put target back
     //
     fs.completeLocalOutput(outputIndex, tmpLocalOutput);
-    FileSystem.getLocal(conf).delete(localWorkingDir);
     if (LOG.isInfoEnabled()) { LOG.info("done merging"); }
   }
 
@@ -125,9 +127,10 @@
     // Parse args, read all index directories to be processed
     //
     FileSystem fs = FileSystem.get(conf);
-    List indexDirs = new ArrayList();
+    List<Path> indexDirs = new ArrayList<Path>();
 
-    Path workDir = null;
+    Path workDir = new Path("indexmerger-" + System.currentTimeMillis());
+    
     int i = 0;
     if ("-workingdir".equals(args[i])) {
       i++;
@@ -153,5 +156,8 @@
       LOG.fatal("IndexMerger: " + StringUtils.stringifyException(e));
       return -1;
     }
+    finally {
+      FileSystem.getLocal(conf).delete(workDir);
+    }
   }
 }
