Buggy code:
public class IndexWriter { public static long WRITE_LOCK_TIMEOUT = 1000 ; public static long COMMIT_LOCK_TIMEOUT = 10000 ; public static final String WRITE_LOCK_NAME = "write.lock" ; public static final String COMMIT_LOCK_NAME = "commit.lock" ; private Directory directory ; private Analyzer analyzer ; private Similarity similarity = Similarity . getDefault ( ) ; private SegmentInfos segmentInfos = new SegmentInfos ( ) ; private final Directory ramDirectory = new RAMDirectory ( ) ; private Lock writeLock ; private boolean useCompoundFile = false ; public boolean getUseCompoundFile ( ) { } public void setUseCompoundFile ( boolean value ) { } public void setSimilarity ( Similarity similarity ) { } public Similarity getSimilarity ( ) { } public IndexWriter ( String path , Analyzer a , boolean create ) throws IOException { } public IndexWriter ( File path , Analyzer a , boolean create ) throws IOException { } public IndexWriter ( Directory d , Analyzer a , final boolean create ) throws IOException { } public synchronized void close ( ) throws IOException { } protected void finalize ( ) throws IOException { } public Analyzer getAnalyzer ( ) { } public synchronized int docCount ( ) { } public int maxFieldLength = 10000 ; public void addDocument ( Document doc ) throws IOException { } public void addDocument ( Document doc , Analyzer analyzer ) throws IOException { } private final synchronized String newSegmentName ( ) { } public int mergeFactor = 10 ; public int minMergeDocs = 10 ; public int maxMergeDocs = Integer . MAX_VALUE ; public PrintStream infoStream = null ; public synchronized void optimize ( ) throws IOException { } public synchronized void addIndexes ( Directory [ ] dirs ) throws IOException { } public synchronized void addIndexes ( IndexReader [ ] readers ) throws IOException { optimize ( ) ; String mergedName = newSegmentName ( ) ; SegmentMerger merger = new SegmentMerger ( directory , mergedName , false ) ; if ( ( segmentInfos . size ( ) ) == 1 ) merger . add ( new SegmentReader ( segmentInfos . info ( 0 ) ) ) ; for ( int i = 0 ; i < ( readers . length ) ; i ++ ) merger . add ( readers [ i ] ) ; int docCount = merger . merge ( ) ; segmentInfos . setSize ( 0 ) ; segmentInfos . addElement ( new SegmentInfo ( mergedName , docCount , directory ) ) ; synchronized ( directory ) { <START_BUG> new Lock . With ( directory . makeLock ( "commit.lock" ) ) { <END_BUG> public Object doBody ( ) throws IOException { segmentInfos . write ( directory ) ; return null ; } } . run ( ) ; } } private final void flushRamSegments ( ) throws IOException { } private final void maybeMergeSegments ( ) throws IOException { } private final void mergeSegments ( int minSegment ) throws IOException { } private final void deleteSegments ( Vector segments ) throws IOException { } private final void deleteFiles ( Vector files , Directory directory ) throws IOException { } private final void deleteFiles ( Vector files , Vector deletable ) throws IOException { } private final Vector readDeleteableFiles ( ) throws IOException { } private final void writeDeleteableFiles ( Vector files ) throws IOException { } }

Fix:
new Lock . With ( directory . makeLock ( "commit.lock" ) , IndexWriter . COMMIT_LOCK_TIMEOUT ) {