diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java
index d4cba12fe40..23e7d1b9b6e 100644
--- a/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/src/java/org/apache/lucene/index/IndexWriter.java
@@ -400,7 +400,7 @@ public class IndexWriter {
     optimize();					  // start with zero or 1 seg
 
     String mergedName = newSegmentName();
-    SegmentMerger merger = new SegmentMerger(directory, mergedName, useCompoundFile);
+    final SegmentMerger merger = new SegmentMerger(directory, mergedName);
 
     final Vector segmentsToDelete = new Vector();
     IndexReader sReader = null;
@@ -426,6 +426,8 @@ public class IndexWriter {
 	  public Object doBody() throws IOException {
 	    segmentInfos.write(directory);	  // commit changes
 	    deleteSegments(segmentsToDelete);  // delete now-unused segments
+	    if(useCompoundFile)
+	        merger.createCompoundFile();
 	    return null;
 	  }
 	}.run();
@@ -479,8 +481,8 @@ public class IndexWriter {
       throws IOException {
     String mergedName = newSegmentName();
     if (infoStream != null) infoStream.print("merging segments");
-    SegmentMerger merger =
-        new SegmentMerger(directory, mergedName, useCompoundFile);
+    final SegmentMerger merger =
+        new SegmentMerger(directory, mergedName);
 
     final Vector segmentsToDelete = new Vector();
     for (int i = minSegment; i < segmentInfos.size(); i++) {
@@ -512,6 +514,8 @@ public class IndexWriter {
           public Object doBody() throws IOException {
             segmentInfos.write(directory);     // commit before deleting
             deleteSegments(segmentsToDelete);  // delete now-unused segments
+            if(useCompoundFile)
+                merger.createCompoundFile();
             return null;
           }
         }.run();
diff --git a/src/java/org/apache/lucene/index/SegmentMerger.java b/src/java/org/apache/lucene/index/SegmentMerger.java
index 71555c18872..565ec8c9fa0 100644
--- a/src/java/org/apache/lucene/index/SegmentMerger.java
+++ b/src/java/org/apache/lucene/index/SegmentMerger.java
@@ -37,7 +37,6 @@ import org.apache.lucene.store.RAMOutputStream;
  * @see #add
  */
 final class SegmentMerger {
-  private boolean useCompoundFile;
   private Directory directory;
   private String segment;
 
@@ -56,12 +55,10 @@ final class SegmentMerger {
    * 
    * @param dir The Directory to merge the other segments into
    * @param name The name of the new segment
-   * @param compoundFile true if the new segment should use a compoundFile
    */
-  SegmentMerger(Directory dir, String name, boolean compoundFile) {
+  SegmentMerger(Directory dir, String name) {
     directory = dir;
     segment = name;
-    useCompoundFile = compoundFile;
   }
 
   /**
@@ -96,9 +93,6 @@ final class SegmentMerger {
     if (fieldInfos.hasVectors())
       mergeVectors();
 
-    if (useCompoundFile)
-      createCompoundFile();
-
     return value;
   }
   
@@ -114,7 +108,7 @@ final class SegmentMerger {
     }
   }
 
-  private final void createCompoundFile()
+  final void createCompoundFile()
           throws IOException {
     CompoundFileWriter cfsWriter =
             new CompoundFileWriter(directory, segment + ".cfs");
diff --git a/src/test/org/apache/lucene/index/DocTest.java b/src/test/org/apache/lucene/index/DocTest.java
index 6c9441811e1..7bfa4e45105 100644
--- a/src/test/org/apache/lucene/index/DocTest.java
+++ b/src/test/org/apache/lucene/index/DocTest.java
@@ -76,7 +76,7 @@ class DocTest {
     SegmentReader r1 = new SegmentReader(new SegmentInfo(seg1, 1, directory));
     SegmentReader r2 = new SegmentReader(new SegmentInfo(seg2, 1, directory));
 
-    SegmentMerger merger = new SegmentMerger(directory, merged, false);
+    SegmentMerger merger = new SegmentMerger(directory, merged);
     merger.add(r1);
     merger.add(r2);
     merger.merge();
diff --git a/src/test/org/apache/lucene/index/TestDoc.java b/src/test/org/apache/lucene/index/TestDoc.java
index 557174f7b3c..c8973e41107 100644
--- a/src/test/org/apache/lucene/index/TestDoc.java
+++ b/src/test/org/apache/lucene/index/TestDoc.java
@@ -181,12 +181,15 @@ public class TestDoc extends TestCase {
       SegmentReader r2 = new SegmentReader(new SegmentInfo(seg2, 1, directory));
 
       SegmentMerger merger =
-        new SegmentMerger(directory, merged, useCompoundFile);
+        new SegmentMerger(directory, merged);
 
       merger.add(r1);
       merger.add(r2);
       merger.merge();
       merger.closeReaders();
+      
+      if(useCompoundFile)
+          merger.createCompoundFile();
 
       directory.close();
    }
diff --git a/src/test/org/apache/lucene/index/TestSegmentMerger.java b/src/test/org/apache/lucene/index/TestSegmentMerger.java
index 95c86484e2e..dee8ccf67d4 100644
--- a/src/test/org/apache/lucene/index/TestSegmentMerger.java
+++ b/src/test/org/apache/lucene/index/TestSegmentMerger.java
@@ -72,7 +72,7 @@ public class TestSegmentMerger extends TestCase {
   
   public void testMerge() {                             
     //System.out.println("----------------TestMerge------------------");
-    SegmentMerger merger = new SegmentMerger(mergedDir, mergedSegment, false);
+    SegmentMerger merger = new SegmentMerger(mergedDir, mergedSegment);
     merger.add(reader1);
     merger.add(reader2);
     try {