Program: 86549
Project: 86549
Buggy source:
@Override public void doPost(final HttpServletRequest request,final HttpServletResponse response){
  final String path=request.getServletPath() + (request.getPathInfo() != null ? request.getPathInfo() : "String_Node_Str");
  if ("String_Node_Str".equals(path)) {
    final String key=request.getParameter("String_Node_Str");
    final String value=request.getParameter("String_Node_Str");
    if (Boolean.valueOf(value.toLowerCase())) {
      favouredCamConfSettings.setProperty(key,Boolean.TRUE.toString());
    }
 else {
      favouredCamConfSettings.remove(key);
    }
    redirectSafely(response,request.getContextPath() + "String_Node_Str",logger);
  }
 else   if ("String_Node_Str".equals(path)) {
    final String type=request.getParameter("String_Node_Str");
    final String key=request.getParameter("String_Node_Str");
    final String value=request.getParameter("String_Node_Str");
    final String page=request.getParameter("String_Node_Str");
    final AbstractGPhoto2Command command;
switch (CameraConfigEntryType.valueOf(type)) {
case RADIO:
case MENU:
      command=new GP2CmdSetSettingByIndex(key,Integer.parseInt(value),logger);
    break;
case TOGGLE:
case TEXT:
case DATE:
  command=new GP2CmdSetSetting(key,value,logger);
break;
default :
returnForbidden(request,response);
command=null;
break;
}
if (command != null) {
if (!processCommandFailure(gphoto2CommandService.executeCommand(command),makeVelocityContext(request,response),request,response,logger)) {
redirectSafely(response,request.getContextPath() + (page != null && "String_Node_Str".equals(page) ? "String_Node_Str" : "String_Node_Str"),logger);
}
}
}
 else if ("String_Node_Str".equals(path)) {
final Integer lastPreviewRetriesCount=(Integer)velocityContextService.getGlobalContext().get("String_Node_Str");
int previewRetriesCount=lastPreviewRetriesCount == null ? 0 : lastPreviewRetriesCount.intValue();
boolean success=false;
while (!success && previewRetriesCount < 15) {
final GP2CmdCapturePreview command=gphoto2CommandService.executeCommand(new GP2CmdCapturePreview(logger,"String_Node_Str",true,previewRetriesCount));
if (command.isResultedWithPossibleTimingFailure()) {
previewRetriesCount++;
}
 else {
if (command.getRawErrorOutput() != null && command.getRawErrorOutput().trim().length() > 0) {
processCommandFailure(command,null,request,response,logger);
break;
}
 else {
success=true;
}
}
}
if (success) {
velocityContextService.getGlobalContext().put("String_Node_Str",previewRetriesCount);
redirectSafely(response,request.getContextPath() + "String_Node_Str",logger);
}
}
 else if ("String_Node_Str".equals(path)) {
final int imgRefId=Integer.parseInt(request.getParameter("String_Node_Str"));
if (!processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdGetThumbnail(request.getParameter("String_Node_Str"),imgRefId,"String_Node_Str",logger)),makeVelocityContext(request,response),request,response,logger)) {
redirectSafely(response,request.getContextPath() + "String_Node_Str",logger);
}
}
 else if ("String_Node_Str".equals(path)) {
final int imgRefId=Integer.parseInt(request.getParameter("String_Node_Str"));
if (!processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdDeleteFile(request.getParameter("String_Node_Str"),imgRefId,logger)),makeVelocityContext(request,response),request,response,logger)) {
redirectSafely(response,request.getContextPath() + "String_Node_Str",logger);
}
}
 else if ("String_Node_Str".equals(path)) {
if (!processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdCaptureImage(true,logger)),null,request,response,logger)) {
redirectSafely(response,request.getContextPath() + "String_Node_Str",logger);
}
}
 else if ("String_Node_Str".equals(path)) {
final GP2CmdCaptureImageAndListFiles cmdCaptureAndList=new GP2CmdCaptureImageAndListFiles(null,logger);
if (!processCommandFailure(gphoto2CommandService.executeCommand(cmdCaptureAndList),null,request,response,logger)) {
final String newlyCapturedImagePath=cmdCaptureAndList.getResultFile();
boolean proceed=true;
if (newlyCapturedImagePath != null && cmdCaptureAndList.getFilesList() != null && cmdCaptureAndList.getFilesList().getByFolder() != null && cmdCaptureAndList.getFilesList().getByRefId() != null) {
final int indexOfLastSlash=newlyCapturedImagePath.lastIndexOf("String_Node_Str");
final String fileName=newlyCapturedImagePath.substring(indexOfLastSlash + 1);
final String folderPath=newlyCapturedImagePath.substring(0,indexOfLastSlash);
final Map<String,CameraFileRef> filesInFolder=cmdCaptureAndList.getFilesList().getByFolder().get(folderPath);
if (filesInFolder != null) {
final CameraFileRef resultFileRef=filesInFolder.get(fileName);
if (resultFileRef != null) {
if (processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdGetThumbnail(folderPath,resultFileRef.getRefId(),"String_Node_Str",logger)),null,request,response,logger)) {
proceed=false;
}
}
}
}
if (proceed) {
redirectSafely(response,request.getContextPath() + "String_Node_Str",logger);
}
}
}
}

Fixed version (ground truth):
@Override public void doPost(final HttpServletRequest request,final HttpServletResponse response){
  final String path=request.getServletPath() + (request.getPathInfo() != null ? request.getPathInfo() : "String_Node_Str");
  if ("String_Node_Str".equals(path)) {
    final String key=request.getParameter("String_Node_Str");
    final String value=request.getParameter("String_Node_Str");
    if (Boolean.valueOf(value.toLowerCase())) {
      favouredCamConfSettings.setProperty(key,Boolean.TRUE.toString());
    }
 else {
      favouredCamConfSettings.remove(key);
    }
    redirectLocalSafely(request,response,"String_Node_Str");
  }
 else   if ("String_Node_Str".equals(path)) {
    final String type=request.getParameter("String_Node_Str");
    final String key=request.getParameter("String_Node_Str");
    final String value=request.getParameter("String_Node_Str");
    final String page=request.getParameter("String_Node_Str");
    final AbstractGPhoto2Command command;
switch (CameraConfigEntryType.valueOf(type)) {
case RADIO:
case MENU:
      command=new GP2CmdSetSettingByIndex(key,Integer.parseInt(value),logger);
    break;
case TOGGLE:
case TEXT:
case DATE:
  command=new GP2CmdSetSetting(key,value,logger);
break;
default :
returnForbidden(request,response);
command=null;
break;
}
if (command != null) {
if (!processCommandFailure(gphoto2CommandService.executeCommand(command),makeVelocityContext(request,response),request,response,logger)) {
if (page != null && "String_Node_Str".equals(page)) {
final GP2CmdGetAllCameraConfigurations cameraConfigsCommand=gphoto2CommandService.executeCommand(new GP2CmdGetAllCameraConfigurations(logger));
if (cameraConfigsCommand.getExitCode() == 0) {
velocityContextService.getGlobalContext().put("String_Node_Str",cameraConfigsCommand.getCameraConfig());
}
 else {
logger.warn("String_Node_Str" + cameraConfigsCommand.getRawErrorOutput());
}
redirectLocalSafely(request,response,"String_Node_Str");
}
 else {
redirectLocalSafely(request,response,"String_Node_Str");
}
}
}
}
 else if ("String_Node_Str".equals(path)) {
final Integer lastPreviewRetriesCount=(Integer)velocityContextService.getGlobalContext().get("String_Node_Str");
int previewRetriesCount=lastPreviewRetriesCount == null ? 0 : lastPreviewRetriesCount.intValue();
boolean success=false;
while (!success && previewRetriesCount < 15) {
final GP2CmdCapturePreview command=gphoto2CommandService.executeCommand(new GP2CmdCapturePreview(logger,"String_Node_Str",true,previewRetriesCount));
if (command.isResultedWithPossibleTimingFailure()) {
previewRetriesCount++;
}
 else {
if (command.getRawErrorOutput() != null && command.getRawErrorOutput().trim().length() > 0) {
processCommandFailure(command,null,request,response,logger);
break;
}
 else {
success=true;
}
}
}
if (success) {
velocityContextService.getGlobalContext().put("String_Node_Str",previewRetriesCount);
redirectLocalSafely(request,response,"String_Node_Str");
}
}
 else if ("String_Node_Str".equals(path)) {
final int imgRefId=Integer.parseInt(request.getParameter("String_Node_Str"));
if (!processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdGetThumbnail(request.getParameter("String_Node_Str"),imgRefId,"String_Node_Str",logger)),makeVelocityContext(request,response),request,response,logger)) {
redirectLocalSafely(request,response,"String_Node_Str");
}
}
 else if ("String_Node_Str".equals(path)) {
final int imgRefId=Integer.parseInt(request.getParameter("String_Node_Str"));
if (!processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdDeleteFile(request.getParameter("String_Node_Str"),imgRefId,logger)),makeVelocityContext(request,response),request,response,logger)) {
redirectLocalSafely(request,response,"String_Node_Str");
}
}
 else if ("String_Node_Str".equals(path)) {
if (!processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdCaptureImage(true,logger)),null,request,response,logger)) {
redirectLocalSafely(request,response,"String_Node_Str");
}
}
 else if ("String_Node_Str".equals(path)) {
final GP2CmdCaptureImageAndListFiles cmdCaptureAndList=new GP2CmdCaptureImageAndListFiles(null,logger);
if (!processCommandFailure(gphoto2CommandService.executeCommand(cmdCaptureAndList),null,request,response,logger)) {
final String newlyCapturedImagePath=cmdCaptureAndList.getResultFile();
boolean proceed=true;
if (newlyCapturedImagePath != null && cmdCaptureAndList.getFilesList() != null && cmdCaptureAndList.getFilesList().getByFolder() != null && cmdCaptureAndList.getFilesList().getByRefId() != null) {
final int indexOfLastSlash=newlyCapturedImagePath.lastIndexOf("String_Node_Str");
final String fileName=newlyCapturedImagePath.substring(indexOfLastSlash + 1);
final String folderPath=newlyCapturedImagePath.substring(0,indexOfLastSlash);
final Map<String,CameraFileRef> filesInFolder=cmdCaptureAndList.getFilesList().getByFolder().get(folderPath);
if (filesInFolder != null) {
final CameraFileRef resultFileRef=filesInFolder.get(fileName);
if (resultFileRef != null) {
if (processCommandFailure(gphoto2CommandService.executeCommand(new GP2CmdGetThumbnail(folderPath,resultFileRef.getRefId(),"String_Node_Str",logger)),null,request,response,logger)) {
proceed=false;
}
}
}
}
if (proceed) {
redirectLocalSafely(request,response,"String_Node_Str");
}
}
}
}