Program: 113845
Project: 113845
Buggy source:
/** 
 * Parse the Locations header
 * @param rq the request
 * @param loc the locations header string
 * @return an error, null if successfull
 */
protected ErrorRecord parseLocations(OSDRequest rq,String loc){
  int locVer=-1;
  try {
    int lastComma=loc.lastIndexOf(',');
    String lastArg=loc.substring(lastComma + 1,loc.length() - 1);
    if (lastArg.indexOf('"') >= 0) {
      int sndLastComma=loc.substring(0,lastComma).lastIndexOf(',');
      String tmp=loc.substring(sndLastComma + 1,lastComma);
      tmp=tmp.trim();
      locVer=Integer.parseInt(tmp);
    }
 else {
      lastArg=lastArg.trim();
      locVer=Integer.parseInt(lastArg);
    }
  }
 catch (  Exception e) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,null,e);
    }
    return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.INVALID_HEADER,HTTPHeaders.HDR_XLOCATIONS + "String_Node_Str",e);
  }
  Locations cachedLoc=xLocCache.getLocations(rq.getDetails().getFileId());
  if ((cachedLoc != null) && (cachedLoc.getVersion() == locVer)) {
    rq.getDetails().setLocationList(cachedLoc);
  }
 else {
    try {
      Locations receivedLoc=new Locations(new JSONString(loc));
      if ((receivedLoc.getNumberOfReplicas() == 0) && (cachedLoc == null)) {
        return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.NEED_FULL_XLOC,"String_Node_Str");
      }
      if ((cachedLoc != null) && (cachedLoc.getVersion() > locVer)) {
        return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.XLOC_OUTDATED,"String_Node_Str" + cachedLoc.getVersion() + "String_Node_Str"+ locVer);
      }
      xLocCache.update(rq.getDetails().getFileId(),receivedLoc);
      rq.getDetails().setLocationList(receivedLoc);
    }
 catch (    JSONException ex) {
      return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.INVALID_HEADER,"String_Node_Str",ex);
    }
  }
  try {
    rq.getDetails().getLocationList().resolveAll();
  }
 catch (  UnknownUUIDException ex) {
    return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.INVALID_HEADER,"String_Node_Str" + ex);
  }
  final Location currentReplica=rq.getDetails().getLocationList().getLocation(master.getConfig().getUUID());
  if (currentReplica == null) {
    return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.NOT_IN_XLOC,"String_Node_Str" + master.getConfig().getUUID() + "String_Node_Str");
  }
  rq.getDetails().setCurrentReplica(currentReplica);
  return null;
}

Fixed version (ground truth):
/** 
 * Parse the Locations header
 * @param rq the request
 * @param loc the locations header string
 * @return an error, null if successfull
 */
protected ErrorRecord parseLocations(OSDRequest rq,String loc){
  int locVer=-1;
  try {
    int lastComma=loc.lastIndexOf(',');
    String lastArg=loc.substring(lastComma + 1,loc.length() - 1);
    if (lastArg.indexOf('"') >= 0) {
      int sndLastComma=loc.substring(0,lastComma).lastIndexOf(',');
      String tmp=loc.substring(sndLastComma + 1,lastComma);
      tmp=tmp.trim();
      locVer=Integer.parseInt(tmp);
    }
 else {
      lastArg=lastArg.trim();
      locVer=Integer.parseInt(lastArg);
    }
  }
 catch (  Exception e) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,null,e);
    }
    return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.INVALID_HEADER,HTTPHeaders.HDR_XLOCATIONS + "String_Node_Str",e);
  }
  Locations cachedLoc=xLocCache.getLocations(rq.getDetails().getFileId());
  if ((cachedLoc != null) && (cachedLoc.getVersion() == locVer)) {
    rq.getDetails().setLocationList(cachedLoc);
  }
 else {
    try {
      Locations receivedLoc=new Locations(new JSONString(loc));
      if ((receivedLoc.getNumberOfReplicas() == 0) && (cachedLoc == null)) {
        return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.NEED_FULL_XLOC,"String_Node_Str");
      }
      if ((cachedLoc != null) && (cachedLoc.getVersion() > locVer)) {
        return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.XLOC_OUTDATED,"String_Node_Str" + cachedLoc.getVersion() + "String_Node_Str"+ locVer);
      }
      xLocCache.update(rq.getDetails().getFileId(),receivedLoc);
      rq.getDetails().setLocationList(receivedLoc);
    }
 catch (    JSONException ex) {
      return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.INVALID_HEADER,"String_Node_Str",ex);
    }
catch (    ClassCastException ex) {
      return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.INVALID_HEADER,"String_Node_Str",ex);
    }
  }
  try {
    rq.getDetails().getLocationList().resolveAll();
  }
 catch (  UnknownUUIDException ex) {
    return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.INVALID_HEADER,"String_Node_Str" + ex);
  }
  final Location currentReplica=rq.getDetails().getLocationList().getLocation(master.getConfig().getUUID());
  if (currentReplica == null) {
    return new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrorCodes.NOT_IN_XLOC,"String_Node_Str" + master.getConfig().getUUID() + "String_Node_Str");
  }
  rq.getDetails().setCurrentReplica(currentReplica);
  return null;
}