Buggy code:
public final class SegmentInfos extends Vector < SegmentInfo > { public static final int FORMAT = - 1 ; public static final int FORMAT_LOCKLESS = - 2 ; public static final int FORMAT_SINGLE_NORM_FILE = - 3 ; public static final int FORMAT_SHARED_DOC_STORE = - 4 ; public static final int FORMAT_CHECKSUM = - 5 ; public static final int FORMAT_DEL_COUNT = - 6 ; public static final int FORMAT_HAS_PROX = - 7 ; public static final int FORMAT_USER_DATA = - 8 ; public static final int FORMAT_DIAGNOSTICS = - 9 ; static final int CURRENT_FORMAT = SegmentInfos . FORMAT_DIAGNOSTICS ; public int counter = 0 ; private long version = System . currentTimeMillis ( ) ; private long generation = 0 ; private long lastGeneration = 0 ; private Map < String , String > userData = Collections . < String , String > emptyMap ( ) ; private static PrintStream infoStream ; public final SegmentInfo info ( int i ) { } public static long getCurrentSegmentGeneration ( String [ ] files ) { } public static long getCurrentSegmentGeneration ( Directory directory ) throws IOException { } public static String getCurrentSegmentFileName ( String [ ] files ) throws IOException { } public static String getCurrentSegmentFileName ( Directory directory ) throws IOException { } public String getCurrentSegmentFileName ( ) { } public static long generationFromSegmentsFileName ( String fileName ) { } public String getNextSegmentFileName ( ) { } public final void read ( Directory directory , String segmentFileName ) throws IOException , CorruptIndexException { } public final void read ( Directory directory ) throws IOException , CorruptIndexException { } ChecksumIndexOutput pendingSegnOutput ; private final void write ( Directory directory ) throws IOException { } @ Override public Object clone ( ) { } public long getVersion ( ) { } public long getGeneration ( ) { } public long getLastGeneration ( ) { } public static long readCurrentVersion ( Directory directory ) throws IOException , CorruptIndexException { } public static Map < String , String > readCurrentUserData ( Directory directory ) throws IOException , CorruptIndexException { } public static void setInfoStream ( PrintStream infoStream ) { } private static int defaultGenFileRetryCount = 10 ; private static int defaultGenFileRetryPauseMsec = 50 ; private static int defaultGenLookaheadCount = 10 ; public static void setDefaultGenFileRetryCount ( int count ) { } public static int getDefaultGenFileRetryCount ( ) { } public static void setDefaultGenFileRetryPauseMsec ( int msec ) { } public static int getDefaultGenFileRetryPauseMsec ( ) { } public static void setDefaultGenLookaheadCount ( int count ) { } public static int getDefaultGenLookahedCount ( ) { } public static PrintStream getInfoStream ( ) { } private static void message ( String message ) { } public abstract static class FindSegmentsFile { final Directory directory ; public FindSegmentsFile ( Directory directory ) { } public Object run ( ) throws IOException , CorruptIndexException { } public Object run ( IndexCommit commit ) throws IOException , CorruptIndexException { } protected abstract Object doBody ( String segmentFileName ) throws IOException , CorruptIndexException { } } public SegmentInfos range ( int first , int last ) { } void updateGeneration ( SegmentInfos other ) { } final void rollbackCommit ( Directory dir ) throws IOException { } final void prepareCommit ( Directory dir ) throws IOException { } public Collection < String > files ( Directory dir , boolean includeSegmentsFile ) throws IOException { } final void finishCommit ( Directory dir ) throws IOException { if ( ( pendingSegnOutput ) == null ) throw new IllegalStateException ( "prepareCommit<seq2seq4repair_space>was<seq2seq4repair_space>not<seq2seq4repair_space>called" ) ; boolean success = false ; try { pendingSegnOutput . finishCommit ( ) ; pendingSegnOutput . close ( ) ; pendingSegnOutput = null ; success = true ; } finally { if ( ! success ) rollbackCommit ( dir ) ; } final String fileName = IndexFileNames . fileNameFromGeneration ( SEGMENTS , "" , generation ) ; success = false ; try { <START_BUG> dir . sync ( fileName ) ; <END_BUG> success = true ; } finally { if ( ! success ) { try { dir . deleteFile ( fileName ) ; } catch ( Throwable t ) { } } } lastGeneration = generation ; try { IndexOutput genOutput = dir . createOutput ( SEGMENTS_GEN ) ; try { genOutput . writeInt ( SegmentInfos . FORMAT_LOCKLESS ) ; genOutput . writeLong ( generation ) ; genOutput . writeLong ( generation ) ; } finally { genOutput . close ( ) ; } } catch ( Throwable t ) { } } final void commit ( Directory dir ) throws IOException { } public synchronized String toString ( Directory directory ) { } public Map < String , String > getUserData ( ) { } void setUserData ( Map < String , String > data ) { } void replace ( SegmentInfos other ) { } public boolean hasExternalSegments ( Directory dir ) { } public int totalDocCount ( ) { } }

Fix:
dir . sync ( Collections . singleton ( fileName ) ) ;