Program: 196414
Project: 196414
Buggy source:
@Override public void run(){
  ArraySet<Integer> persistentTaskIds=new ArraySet<Integer>();
  while (true) {
    final boolean probablyDone;
synchronized (TaskPersister.this) {
      probablyDone=mWriteQueue.isEmpty();
    }
    if (probablyDone) {
      if (DEBUG)       Slog.d(TAG,"String_Node_Str");
      persistentTaskIds.clear();
synchronized (mService) {
        final ArrayList<TaskRecord> tasks=mService.mRecentTasks;
        if (DEBUG)         Slog.d(TAG,"String_Node_Str" + tasks);
        for (int taskNdx=tasks.size() - 1; taskNdx >= 0; --taskNdx) {
          final TaskRecord task=tasks.get(taskNdx);
          if (DEBUG)           Slog.d(TAG,"String_Node_Str" + task + "String_Node_Str"+ task.isPersistable);
          if (task.isPersistable && !task.stack.isHomeStack()) {
            if (DEBUG)             Slog.d(TAG,"String_Node_Str" + task);
            persistentTaskIds.add(task.taskId);
          }
 else {
            if (DEBUG)             Slog.d(TAG,"String_Node_Str" + task);
          }
        }
      }
      removeObsoleteFiles(persistentTaskIds);
    }
    final WriteQueueItem item;
synchronized (TaskPersister.this) {
      if (mNextWriteTime != FLUSH_QUEUE) {
        mNextWriteTime=SystemClock.uptimeMillis() + INTER_WRITE_DELAY_MS;
        if (DEBUG)         Slog.d(TAG,"String_Node_Str" + INTER_WRITE_DELAY_MS + "String_Node_Str"+ mNextWriteTime+ "String_Node_Str");
      }
      while (mWriteQueue.isEmpty()) {
        if (mNextWriteTime != 0) {
          mNextWriteTime=0;
          TaskPersister.this.notifyAll();
        }
        try {
          if (DEBUG)           Slog.d(TAG,"String_Node_Str");
          TaskPersister.this.wait();
        }
 catch (        InterruptedException e) {
        }
      }
      item=mWriteQueue.remove(0);
      long now=SystemClock.uptimeMillis();
      if (DEBUG)       Slog.d(TAG,"String_Node_Str" + now + "String_Node_Str"+ mNextWriteTime+ "String_Node_Str"+ mWriteQueue.size());
      while (now < mNextWriteTime) {
        try {
          if (DEBUG)           Slog.d(TAG,"String_Node_Str" + (mNextWriteTime - now));
          TaskPersister.this.wait(mNextWriteTime - now);
        }
 catch (        InterruptedException e) {
        }
        now=SystemClock.uptimeMillis();
      }
    }
    if (item instanceof ImageWriteQueueItem) {
      ImageWriteQueueItem imageWriteQueueItem=(ImageWriteQueueItem)item;
      final String filename=imageWriteQueueItem.mFilename;
      final Bitmap bitmap=imageWriteQueueItem.mImage;
      if (DEBUG)       Slog.d(TAG,"String_Node_Str" + filename);
      FileOutputStream imageFile=null;
      try {
        imageFile=new FileOutputStream(new File(sImagesDir,filename));
        bitmap.compress(Bitmap.CompressFormat.PNG,100,imageFile);
      }
 catch (      Exception e) {
        Slog.e(TAG,"String_Node_Str" + filename,e);
      }
 finally {
        if (imageFile != null) {
          try {
            imageFile.close();
          }
 catch (          IOException e) {
          }
        }
      }
    }
 else     if (item instanceof TaskWriteQueueItem) {
      StringWriter stringWriter=null;
      TaskRecord task=((TaskWriteQueueItem)item).mTask;
      if (DEBUG)       Slog.d(TAG,"String_Node_Str" + task);
synchronized (mService) {
        if (task.inRecents) {
          try {
            if (DEBUG)             Slog.d(TAG,"String_Node_Str" + task);
            stringWriter=saveToXml(task);
          }
 catch (          IOException e) {
          }
catch (          XmlPullParserException e) {
          }
        }
      }
      if (stringWriter != null) {
        FileOutputStream file=null;
        AtomicFile atomicFile=null;
        try {
          atomicFile=new AtomicFile(new File(sTasksDir,String.valueOf(task.taskId) + RECENTS_FILENAME + TASK_EXTENSION));
          file=atomicFile.startWrite();
          file.write(stringWriter.toString().getBytes());
          file.write('\n');
          atomicFile.finishWrite(file);
        }
 catch (        IOException e) {
          if (file != null) {
            atomicFile.failWrite(file);
          }
          Slog.e(TAG,"String_Node_Str" + atomicFile + "String_Node_Str"+ e);
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  ArraySet<Integer> persistentTaskIds=new ArraySet<Integer>();
  while (true) {
    final boolean probablyDone;
synchronized (TaskPersister.this) {
      probablyDone=mWriteQueue.isEmpty();
    }
    if (probablyDone) {
      if (DEBUG)       Slog.d(TAG,"String_Node_Str");
      persistentTaskIds.clear();
synchronized (mService) {
        final ArrayList<TaskRecord> tasks=mService.mRecentTasks;
        if (DEBUG)         Slog.d(TAG,"String_Node_Str" + tasks);
        for (int taskNdx=tasks.size() - 1; taskNdx >= 0; --taskNdx) {
          final TaskRecord task=tasks.get(taskNdx);
          if (DEBUG)           Slog.d(TAG,"String_Node_Str" + task + "String_Node_Str"+ task.isPersistable);
          if ((task.isPersistable || task.inRecents) && !task.stack.isHomeStack()) {
            if (DEBUG)             Slog.d(TAG,"String_Node_Str" + task);
            persistentTaskIds.add(task.taskId);
          }
 else {
            if (DEBUG)             Slog.d(TAG,"String_Node_Str" + task);
          }
        }
      }
      removeObsoleteFiles(persistentTaskIds);
    }
    final WriteQueueItem item;
synchronized (TaskPersister.this) {
      if (mNextWriteTime != FLUSH_QUEUE) {
        mNextWriteTime=SystemClock.uptimeMillis() + INTER_WRITE_DELAY_MS;
        if (DEBUG)         Slog.d(TAG,"String_Node_Str" + INTER_WRITE_DELAY_MS + "String_Node_Str"+ mNextWriteTime+ "String_Node_Str");
      }
      while (mWriteQueue.isEmpty()) {
        if (mNextWriteTime != 0) {
          mNextWriteTime=0;
          TaskPersister.this.notifyAll();
        }
        try {
          if (DEBUG)           Slog.d(TAG,"String_Node_Str");
          TaskPersister.this.wait();
        }
 catch (        InterruptedException e) {
        }
      }
      item=mWriteQueue.remove(0);
      long now=SystemClock.uptimeMillis();
      if (DEBUG)       Slog.d(TAG,"String_Node_Str" + now + "String_Node_Str"+ mNextWriteTime+ "String_Node_Str"+ mWriteQueue.size());
      while (now < mNextWriteTime) {
        try {
          if (DEBUG)           Slog.d(TAG,"String_Node_Str" + (mNextWriteTime - now));
          TaskPersister.this.wait(mNextWriteTime - now);
        }
 catch (        InterruptedException e) {
        }
        now=SystemClock.uptimeMillis();
      }
    }
    if (item instanceof ImageWriteQueueItem) {
      ImageWriteQueueItem imageWriteQueueItem=(ImageWriteQueueItem)item;
      final String filename=imageWriteQueueItem.mFilename;
      final Bitmap bitmap=imageWriteQueueItem.mImage;
      if (DEBUG)       Slog.d(TAG,"String_Node_Str" + filename);
      FileOutputStream imageFile=null;
      try {
        imageFile=new FileOutputStream(new File(sImagesDir,filename));
        bitmap.compress(Bitmap.CompressFormat.PNG,100,imageFile);
      }
 catch (      Exception e) {
        Slog.e(TAG,"String_Node_Str" + filename,e);
      }
 finally {
        if (imageFile != null) {
          try {
            imageFile.close();
          }
 catch (          IOException e) {
          }
        }
      }
    }
 else     if (item instanceof TaskWriteQueueItem) {
      StringWriter stringWriter=null;
      TaskRecord task=((TaskWriteQueueItem)item).mTask;
      if (DEBUG)       Slog.d(TAG,"String_Node_Str" + task);
synchronized (mService) {
        if (task.inRecents) {
          try {
            if (DEBUG)             Slog.d(TAG,"String_Node_Str" + task);
            stringWriter=saveToXml(task);
          }
 catch (          IOException e) {
          }
catch (          XmlPullParserException e) {
          }
        }
      }
      if (stringWriter != null) {
        FileOutputStream file=null;
        AtomicFile atomicFile=null;
        try {
          atomicFile=new AtomicFile(new File(sTasksDir,String.valueOf(task.taskId) + RECENTS_FILENAME + TASK_EXTENSION));
          file=atomicFile.startWrite();
          file.write(stringWriter.toString().getBytes());
          file.write('\n');
          atomicFile.finishWrite(file);
        }
 catch (        IOException e) {
          if (file != null) {
            atomicFile.failWrite(file);
          }
          Slog.e(TAG,"String_Node_Str" + atomicFile + "String_Node_Str"+ e);
        }
      }
    }
  }
}