Buggy code:
public JobId getJobId ( ) { } public synchronized Path getConfFile ( ) { } public synchronized Configuration loadConfFile ( ) throws IOException { } } private HistoryFileManager . SerialNumberIndex serialNumberIndex = null ; protected HistoryFileManager . JobListCache jobListCache = null ; private final Set < Path > existingDoneSubdirs = Collections . synchronizedSet ( new HashSet < Path > ( ) ) ; private ConcurrentMap < String , HistoryFileManager . UserLogDir > userDirModificationTimeMap = new ConcurrentHashMap < String , HistoryFileManager . UserLogDir > ( ) ; private JobACLsManager aclsMgr ; @ VisibleForTesting Configuration conf ; private String serialNumberFormat ; private Path doneDirPrefixPath = null ; private FileContext doneDirFc ; private Path intermediateDoneDirPath = null ; private FileContext intermediateDoneDirFc ; @ VisibleForTesting protected ThreadPoolExecutor moveToDoneExecutor = null ; private long maxHistoryAge = 0 ; public HistoryFileManager ( ) { } @ Override protected void serviceInit ( Configuration conf ) throws Exception { } @ VisibleForTesting void createHistoryDirs ( Clock clock , long intervalCheckMillis , long timeOutMillis ) throws IOException { } private boolean isBecauseSafeMode ( Throwable ex ) { } @ VisibleForTesting boolean tryCreatingHistoryDirs ( boolean logWait ) throws IOException { } @ Override public void serviceStop ( ) throws Exception { } protected HistoryFileManager . JobListCache createJobListCache ( ) { } private void mkdir ( FileContext fc , Path path , FsPermission fsp ) throws IOException { } @ SuppressWarnings ( "unchecked" ) void initExisting ( ) throws IOException { } private void removeDirectoryFromSerialNumberIndex ( Path serialDirPath ) { } private void addDirectoryToSerialNumberIndex ( Path serialDirPath ) { } private void addDirectoryToJobListCache ( Path path ) throws IOException { } private static List < FileStatus > scanDirectory ( Path path , FileContext fc , PathFilter pathFilter ) throws IOException { } protected List < FileStatus > scanDirectoryForHistoryFiles ( Path path , FileContext fc ) throws IOException { } protected List < FileStatus > findTimestampedDirectories ( ) throws IOException { } void scanIntermediateDirectory ( ) throws IOException { } private void scanIntermediateDirectory ( final Path absPath ) throws IOException { if ( HistoryFileManager . LOG . isDebugEnabled ( ) ) { HistoryFileManager . LOG . debug ( ( "Scanning<seq2seq4repair_space>intermediate<seq2seq4repair_space>dir<seq2seq4repair_space>" + absPath ) ) ; } List < FileStatus > fileStatusList = scanDirectoryForHistoryFiles ( absPath , intermediateDoneDirFc ) ; if ( HistoryFileManager . LOG . isDebugEnabled ( ) ) { HistoryFileManager . LOG . debug ( ( ( "Found<seq2seq4repair_space>" + ( fileStatusList . size ( ) ) ) + "<seq2seq4repair_space>files" ) ) ; } for ( FileStatus fs : fileStatusList ) { if ( HistoryFileManager . LOG . isDebugEnabled ( ) ) { HistoryFileManager . LOG . debug ( ( "scanning<seq2seq4repair_space>file:<seq2seq4repair_space>" + ( fs . getPath ( ) ) ) ) ; } JobIndexInfo jobIndexInfo = FileNameIndexUtils . getIndexInfo ( fs . getPath ( ) . getName ( ) ) ; String confFileName = JobHistoryUtils . getIntermediateConfFileName ( jobIndexInfo . getJobId ( ) ) ; String summaryFileName = JobHistoryUtils . getIntermediateSummaryFileName ( jobIndexInfo . getJobId ( ) ) ; HistoryFileManager . HistoryFileInfo fileInfo = new HistoryFileManager . HistoryFileInfo ( fs . getPath ( ) , new Path ( fs . getPath ( ) . getParent ( ) , confFileName ) , new Path ( fs . getPath ( ) . getParent ( ) , summaryFileName ) , jobIndexInfo , false ) ; final HistoryFileManager . HistoryFileInfo old = jobListCache . addIfAbsent ( fileInfo ) ; if ( ( old == null ) || ( old . didMoveFail ( ) ) ) { final HistoryFileManager . HistoryFileInfo found = ( old == null ) ? fileInfo : old ; long cutoff = ( System . currentTimeMillis ( ) ) - ( maxHistoryAge ) ; if ( ( found . getJobIndexInfo ( ) . getFinishTime ( ) ) <= cutoff ) { try { found . delete ( ) ; } catch ( IOException e ) { HistoryFileManager . LOG . warn ( "Error<seq2seq4repair_space>cleaning<seq2seq4repair_space>up<seq2seq4repair_space>a<seq2seq4repair_space>HistoryFile<seq2seq4repair_space>that<seq2seq4repair_space>is<seq2seq4repair_space>out<seq2seq4repair_space>of<seq2seq4repair_space>date." , e ) ; } } else { if ( HistoryFileManager . LOG . isDebugEnabled ( ) ) { HistoryFileManager . LOG . debug ( ( "Scheduling<seq2seq4repair_space>move<seq2seq4repair_space>to<seq2seq4repair_space>done<seq2seq4repair_space>of<seq2seq4repair_space>" + found ) ) ; } moveToDoneExecutor . execute ( new Runnable ( ) { @ Override public void run ( ) { try { found . moveToDone ( ) ; } catch ( IOException e ) { HistoryFileManager . LOG . info ( ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>process<seq2seq4repair_space>fileInfo<seq2seq4repair_space>for<seq2seq4repair_space>job:<seq2seq4repair_space>" + ( found . getJobId ( ) ) ) , e ) ; } } } ) ; } } else <START_BUG> if ( ( old != null ) && ( ! ( old . isMovePending ( ) ) ) ) { <END_BUG> if ( HistoryFileManager . LOG . isDebugEnabled ( ) ) { HistoryFileManager . LOG . debug ( "Duplicate:<seq2seq4repair_space>deleting" ) ; } fileInfo . delete ( ) ; } } } private HistoryFileManager . HistoryFileInfo getJobFileInfo ( List < FileStatus > fileStatusList , JobId jobId ) throws IOException { } private HistoryFileManager . HistoryFileInfo scanOldDirsForJob ( JobId jobId ) throws IOException { } public Collection < HistoryFileManager . HistoryFileInfo > getAllFileInfo ( ) throws IOException { } public HistoryFileManager . HistoryFileInfo getFileInfo ( JobId jobId ) throws IOException { } private void moveToDoneNow ( final Path src , final Path target ) throws IOException { } private String getJobSummary ( FileContext fc , Path path ) throws IOException { } private void makeDoneSubdir ( Path path ) throws IOException { } private Path canonicalHistoryLogPath ( JobId id , String timestampComponent ) { } private Path canonicalHistoryLogPath ( JobId id , long millisecondTime ) { } private long getEffectiveTimestamp ( long finishTime , FileStatus fileStatus ) { } private void deleteJobFromDone ( HistoryFileManager . HistoryFileInfo fileInfo ) throws IOException { } List < FileStatus > getHistoryDirsForCleaning ( long cutoff ) throws IOException { } @ SuppressWarnings ( "unchecked" ) void clean ( ) throws IOException { } protected boolean deleteDir ( FileStatus serialDir ) throws FileNotFoundException , IOException , UnsupportedFileSystemException , AccessControlException { } @ VisibleForTesting void setMaxHistoryAge ( long newValue ) { } }

Fix:
if ( ! ( old . isMovePending ( ) ) ) {