Buggy code:
private void init ( Directory d , Analyzer a , boolean closeDir , IndexDeletionPolicy deletionPolicy , boolean autoCommit , int maxFieldLength ) throws IOException , CorruptIndexException , LockObtainFailedException { } private void init ( Directory d , Analyzer a , final boolean create , boolean closeDir , IndexDeletionPolicy deletionPolicy , boolean autoCommit , int maxFieldLength ) throws IOException , CorruptIndexException , LockObtainFailedException { } private void setRollbackSegmentInfos ( ) { } public void setMergePolicy ( MergePolicy mp ) { } public MergePolicy getMergePolicy ( ) { } public void setMergeScheduler ( MergeScheduler mergeScheduler ) throws IOException , CorruptIndexException { } public MergeScheduler getMergeScheduler ( ) { } public void setMaxMergeDocs ( int maxMergeDocs ) { } public int getMaxMergeDocs ( ) { } public void setMaxFieldLength ( int maxFieldLength ) { } public int getMaxFieldLength ( ) { } public void setMaxBufferedDocs ( int maxBufferedDocs ) { } private void pushMaxBufferedDocs ( ) { } public int getMaxBufferedDocs ( ) { } public void setRAMBufferSizeMB ( double mb ) { } public double getRAMBufferSizeMB ( ) { } public void setMaxBufferedDeleteTerms ( int maxBufferedDeleteTerms ) { } public int getMaxBufferedDeleteTerms ( ) { } public void setMergeFactor ( int mergeFactor ) { } public int getMergeFactor ( ) { } public double getMaxSyncPauseSeconds ( ) { } public void setMaxSyncPauseSeconds ( double seconds ) { } public static void setDefaultInfoStream ( PrintStream infoStream ) { } public static PrintStream getDefaultInfoStream ( ) { } public void setInfoStream ( PrintStream infoStream ) { } private void messageState ( ) { } public PrintStream getInfoStream ( ) { } public void setWriteLockTimeout ( long writeLockTimeout ) { } public long getWriteLockTimeout ( ) { } public static void setDefaultWriteLockTimeout ( long writeLockTimeout ) { } public static long getDefaultWriteLockTimeout ( ) { } public void close ( ) throws IOException , CorruptIndexException { } public void close ( boolean waitForMerges ) throws IOException , CorruptIndexException { } private synchronized void waitForClose ( ) { } private void closeInternal ( boolean waitForMerges ) throws IOException , CorruptIndexException { } private synchronized boolean flushDocStores ( ) throws IOException { } protected void finalize ( ) throws Throwable { } public Directory getDirectory ( ) { } public Analyzer getAnalyzer ( ) { } public synchronized int docCount ( ) { } public synchronized boolean hasDeletions ( ) throws IOException { } private int maxFieldLength ; public void addDocument ( Document doc ) throws IOException , CorruptIndexException { } public void addDocument ( Document doc , Analyzer analyzer ) throws IOException , CorruptIndexException { } public void deleteDocuments ( Term term ) throws IOException , CorruptIndexException { } public void deleteDocuments ( Term [ ] terms ) throws IOException , CorruptIndexException { } public void deleteDocuments ( Query query ) throws IOException , CorruptIndexException { } public void deleteDocuments ( Query [ ] queries ) throws IOException , CorruptIndexException { } public void updateDocument ( Term term , Document doc ) throws IOException , CorruptIndexException { } public void updateDocument ( Term term , Document doc , Analyzer analyzer ) throws IOException , CorruptIndexException { } final synchronized int getSegmentCount ( ) { } final synchronized int getNumBufferedDocuments ( ) { } final synchronized int getDocCount ( int i ) { } final synchronized int getFlushCount ( ) { } final synchronized int getFlushDeletesCount ( ) { } final String newSegmentName ( ) { } private PrintStream infoStream = null ; private static PrintStream defaultInfoStream = null ; public void optimize ( ) throws IOException , CorruptIndexException { } public void optimize ( int maxNumSegments ) throws IOException , CorruptIndexException { } public void optimize ( boolean doWait ) throws IOException , CorruptIndexException { <START_BUG> optimize ( 1 , true ) ; <END_BUG> } public void optimize ( int maxNumSegments , boolean doWait ) throws IOException , CorruptIndexException { } private synchronized boolean optimizeMergesPending ( ) { } public void expungeDeletes ( boolean doWait ) throws IOException , CorruptIndexException { } public void expungeDeletes ( ) throws IOException , CorruptIndexException { } public final void maybeMerge ( ) throws IOException , CorruptIndexException { } private final void maybeMerge ( boolean optimize ) throws IOException , CorruptIndexException { } private final void maybeMerge ( int maxNumSegmentsOptimize , boolean optimize ) throws IOException , CorruptIndexException { } private synchronized void updatePendingMerges ( int maxNumSegmentsOptimize , boolean optimize ) throws IOException , CorruptIndexException { } synchronized OneMerge getNextMerge ( ) { } private synchronized void startTransaction ( ) throws IOException { } private synchronized void rollbackTransaction ( ) throws IOException { } private synchronized void commitTransaction ( ) throws IOException { } public void abort ( ) throws IOException { } private synchronized void finishMerges ( boolean waitForMerges ) throws IOException { } private synchronized void checkpoint ( ) throws IOException { } public void addIndexes ( Directory [ ] dirs ) throws IOException , CorruptIndexException { } private synchronized void resetMergeExceptions ( ) { } public void addIndexesNoOptimize ( Directory [ ] dirs ) throws IOException , CorruptIndexException { } private void copyExternalSegments ( ) throws IOException , CorruptIndexException { } public void addIndexes ( IndexReader [ ] readers ) throws IOException , CorruptIndexException { } void doAfterFlush ( ) throws IOException { } public final void flush ( ) throws IOException , CorruptIndexException { } public final void commit ( ) throws IOException , CorruptIndexException { } private final void commit ( boolean triggerMerges ) throws IOException , CorruptIndexException { } protected final void flush ( boolean triggerMerge , boolean flushDocStores , boolean flushDeletes ) throws IOException , CorruptIndexException { } private final synchronized boolean doFlush ( boolean flushDocStores , boolean flushDeletes ) throws IOException , CorruptIndexException { } public final long ramSizeInBytes ( ) { } public final synchronized int numRamDocs ( ) { } private int ensureContiguousMerge ( MergePolicy . OneMerge merge ) { }

Fix:
optimize ( 1 , doWait ) ;