Program: 47057
Project: 47057
Buggy source:
public void stopped(DLNAResource res){
  if (!(res instanceof RealFile)) {
    return;
  }
  RealFile rf=(RealFile)res;
  double fileDuration=0;
  if (res.getMedia() != null && (res.getMedia().isAudio() || res.getMedia().isVideo())) {
    fileDuration=res.getMedia().getDurationInSeconds();
  }
  double elapsed;
  if (res.getLastStartPosition() == 0) {
    elapsed=(System.currentTimeMillis() - res.getStartTime()) / 1000;
  }
 else {
    elapsed=(System.currentTimeMillis() - res.getLastStartSystemTime()) / 1000;
    elapsed+=res.getLastStartPosition();
  }
  FullyPlayedAction fullyPlayedAction=configuration.getFullyPlayedAction();
  if (!fullyPlayedAction.equals(FullyPlayedAction.NO_ACTION)) {
    LOGGER.trace("String_Node_Str");
    LOGGER.trace("String_Node_Str" + fileDuration);
    LOGGER.trace("String_Node_Str" + res.getLastStartPosition());
    LOGGER.trace("String_Node_Str" + res.getStartTime());
    LOGGER.trace("String_Node_Str" + res.getLastStartSystemTime());
    LOGGER.trace("String_Node_Str" + elapsed);
    LOGGER.trace("String_Node_Str" + (fileDuration * configuration.getResumeBackFactor()));
  }
  if ((res.getMedia() != null && res.getMedia().isImage()) || (fileDuration > configuration.getMinimumWatchedPlayTimeSeconds() && elapsed >= (fileDuration * configuration.getResumeBackFactor()))) {
    DLNAResource tmp=res.getParent();
    if (tmp != null) {
      boolean isMonitored=false;
      File[] foldersMonitored=PMS.get().getSharedFoldersArray(true);
      if (foldersMonitored != null && foldersMonitored.length > 0) {
        for (        File folderMonitored : foldersMonitored) {
          if (rf.getFile().getAbsolutePath().contains(folderMonitored.getAbsolutePath())) {
            isMonitored=true;
          }
        }
      }
      if (isMonitored) {
        if (isFullyPlayed(rf.getFile().getAbsolutePath())) {
          return;
        }
        fullyPlayedEntries.add(rf.getFile().getAbsolutePath());
        setDiscovered(false);
        getChildren().clear();
        try {
          dumpFile();
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str" + e);
        }
        File playedFile=new File(rf.getFile().getAbsolutePath());
        if (fullyPlayedAction == FullyPlayedAction.MOVE_FOLDER) {
          String newDirectory=FileUtil.appendPathSeparator(configuration.getFullyPlayedOutputDirectory());
          if (playedFile.renameTo(new File(newDirectory + playedFile.getName()))) {
            LOGGER.debug("String_Node_Str",playedFile.getName());
          }
 else {
            LOGGER.debug("String_Node_Str",playedFile.getName());
            try {
              Thread.sleep(3000);
              if (playedFile.renameTo(new File(newDirectory + playedFile.getName()))) {
                LOGGER.debug("String_Node_Str",playedFile.getName());
              }
 else {
                LOGGER.info("String_Node_Str",playedFile.getName());
              }
            }
 catch (            InterruptedException e) {
              LOGGER.warn("String_Node_Str",e.getMessage());
              LOGGER.trace("String_Node_Str",e);
              Thread.currentThread().interrupt();
            }
          }
        }
 else         if (fullyPlayedAction == FullyPlayedAction.MOVE_TRASH) {
          try {
            if (Platform.isLinux()) {
              FreedesktopTrash.moveToTrash(playedFile);
            }
 else {
              FileUtils.getInstance().moveToTrash(Arrays.array(playedFile));
            }
          }
 catch (          IOException|FileUtil.InvalidFileSystemException e) {
            LOGGER.warn("String_Node_Str",playedFile.getAbsoluteFile(),e.getMessage());
            LOGGER.trace("String_Node_Str",e);
          }
        }
        LOGGER.info("String_Node_Str",playedFile.getName());
      }
    }
  }
 else {
    LOGGER.trace("String_Node_Str");
  }
}

Fixed version (ground truth):
public void stopped(DLNAResource res){
  if (!(res instanceof RealFile)) {
    return;
  }
  RealFile rf=(RealFile)res;
  double fileDuration=0;
  if (res.getMedia() != null && (res.getMedia().isAudio() || res.getMedia().isVideo())) {
    fileDuration=res.getMedia().getDurationInSeconds();
  }
  double elapsed;
  if (res.getLastStartPosition() == 0) {
    elapsed=(double)(System.currentTimeMillis() - res.getStartTime()) / 1000;
  }
 else {
    elapsed=(double)(System.currentTimeMillis() - res.getLastStartSystemTime()) / 1000;
    elapsed+=res.getLastStartPosition();
  }
  FullyPlayedAction fullyPlayedAction=configuration.getFullyPlayedAction();
  if (!fullyPlayedAction.equals(FullyPlayedAction.NO_ACTION)) {
    LOGGER.trace("String_Node_Str");
    LOGGER.trace("String_Node_Str" + fileDuration);
    LOGGER.trace("String_Node_Str" + res.getLastStartPosition());
    LOGGER.trace("String_Node_Str" + res.getStartTime());
    LOGGER.trace("String_Node_Str" + res.getLastStartSystemTime());
    LOGGER.trace("String_Node_Str" + elapsed);
    LOGGER.trace("String_Node_Str" + (fileDuration * configuration.getResumeBackFactor()));
  }
  if ((res.getMedia() != null && res.getMedia().isImage()) || (fileDuration > configuration.getMinimumWatchedPlayTimeSeconds() && elapsed >= (fileDuration * configuration.getResumeBackFactor()))) {
    DLNAResource tmp=res.getParent();
    if (tmp != null) {
      boolean isMonitored=false;
      File[] foldersMonitored=PMS.get().getSharedFoldersArray(true);
      if (foldersMonitored != null && foldersMonitored.length > 0) {
        for (        File folderMonitored : foldersMonitored) {
          if (rf.getFile().getAbsolutePath().contains(folderMonitored.getAbsolutePath())) {
            isMonitored=true;
          }
        }
      }
      if (isMonitored) {
        if (isFullyPlayed(rf.getFile().getAbsolutePath())) {
          return;
        }
        fullyPlayedEntries.add(rf.getFile().getAbsolutePath());
        setDiscovered(false);
        getChildren().clear();
        try {
          dumpFile();
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str" + e);
        }
        File playedFile=new File(rf.getFile().getAbsolutePath());
        if (fullyPlayedAction == FullyPlayedAction.MOVE_FOLDER) {
          String newDirectory=FileUtil.appendPathSeparator(configuration.getFullyPlayedOutputDirectory());
          if (playedFile.renameTo(new File(newDirectory + playedFile.getName()))) {
            LOGGER.debug("String_Node_Str",playedFile.getName());
          }
 else {
            LOGGER.debug("String_Node_Str",playedFile.getName());
            try {
              Thread.sleep(3000);
              if (playedFile.renameTo(new File(newDirectory + playedFile.getName()))) {
                LOGGER.debug("String_Node_Str",playedFile.getName());
              }
 else {
                LOGGER.info("String_Node_Str",playedFile.getName());
              }
            }
 catch (            InterruptedException e) {
              LOGGER.warn("String_Node_Str",e.getMessage());
              LOGGER.trace("String_Node_Str",e);
              Thread.currentThread().interrupt();
            }
          }
        }
 else         if (fullyPlayedAction == FullyPlayedAction.MOVE_TRASH) {
          try {
            if (Platform.isLinux()) {
              FreedesktopTrash.moveToTrash(playedFile);
            }
 else {
              FileUtils.getInstance().moveToTrash(Arrays.array(playedFile));
            }
          }
 catch (          IOException|FileUtil.InvalidFileSystemException e) {
            LOGGER.warn("String_Node_Str",playedFile.getAbsoluteFile(),e.getMessage());
            LOGGER.trace("String_Node_Str",e);
          }
        }
        LOGGER.info("String_Node_Str",playedFile.getName());
      }
    }
  }
 else {
    LOGGER.trace("String_Node_Str");
  }
}