Program: 6593
Project: 6593
Buggy source:
/** 
 * Returns the number of instances for all program runnables that are passed into the data. The data is an array of Json objects where each object must contain the following three elements: appId, programType, and programId (flow name, service name). Retrieving instances only applies to flows, and user services. For flows, another parameter, "runnableId", must be provided. This corresponds to the flowlet/runnable for which to retrieve the instances. <p> Example input: <pre><code> [{"appId": "App1", "programType": "Service", "programId": "Service1", "runnableId": "Runnable1"}, {"appId": "App1", "programType": "Mapreduce", "programId": "Mapreduce2"}, {"appId": "App2", "programType": "Flow", "programId": "Flow1", "runnableId": "Flowlet1"}] </code></pre> </p><p> The response will be an array of JsonObjects each of which will contain the three input parameters as well as 3 fields: <ul> <li>"provisioned" which maps to the number of instances actually provided for the input runnable;</li> <li>"requested" which maps to the number of instances the user has requested for the input runnable; and</li> <li>"statusCode" which maps to the http status code for the data in that JsonObjects (200, 400, 404).</li> </ul> </p><p> If an error occurs in the input (for the example above, Flowlet1 does not exist), then all JsonObjects for which the parameters have a valid instances will have the provisioned and requested fields status code fields but all JsonObjects for which the parameters are not valid will have an error message and statusCode. </p><p> For example, if there is no Flowlet1 in the above data, then the response could be 200 OK with the following data: </p> <pre><code> [{"appId": "App1", "programType": "Service", "programId": "Service1", "runnableId": "Runnable1", "statusCode": 200, "provisioned": 2, "requested": 2}, {"appId": "App1", "programType": "Mapreduce", "programId": "Mapreduce2", "statusCode": 200, "provisioned": 1, "requested": 3}, {"appId": "App2", "programType": "Flow", "programId": "Flow1", "runnableId": "Flowlet1", "statusCode": 404, "error": "Program": Flowlet1 not found"}] </code></pre>
 */
@POST @Path("String_Node_Str") public void getInstances(HttpRequest request,HttpResponder responder,@PathParam("String_Node_Str") String namespaceId){
  try {
    List<BatchEndpointInstances> args=instancesFromBatchArgs(decodeArrayArguments(request,responder));
    if (args == null) {
      return;
    }
    for (    BatchEndpointInstances requestedObj : args) {
      Id.Application appId=Id.Application.from(namespaceId,requestedObj.getAppId());
      ApplicationSpecification spec=store.getApplication(appId);
      if (spec == null) {
        addCodeError(requestedObj,HttpResponseStatus.NOT_FOUND.getCode(),"String_Node_Str" + appId + "String_Node_Str");
        continue;
      }
      ProgramType programType=ProgramType.valueOfPrettyName(requestedObj.getProgramType());
      if (!canHaveInstances(programType)) {
        addCodeError(requestedObj,HttpResponseStatus.BAD_REQUEST.getCode(),"String_Node_Str" + programType + "String_Node_Str");
        continue;
      }
      Id.Program programId=Id.Program.from(appId,programType,requestedObj.getProgramId());
      populateProgramInstances(requestedObj,spec,programId);
    }
    responder.sendJson(HttpResponseStatus.OK,args);
  }
 catch (  SecurityException e) {
    responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
  }
catch (  JsonSyntaxException e) {
    responder.sendStatus(HttpResponseStatus.BAD_REQUEST);
  }
catch (  Throwable e) {
    LOG.error("String_Node_Str",e);
    responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
  }
}

Fixed version (ground truth):
/** 
 * Returns the number of instances for all program runnables that are passed into the data. The data is an array of Json objects where each object must contain the following three elements: appId, programType, and programId (flow name, service name). Retrieving instances only applies to flows, and user services. For flows, another parameter, "runnableId", must be provided. This corresponds to the flowlet/runnable for which to retrieve the instances. <p> Example input: <pre><code> [{"appId": "App1", "programType": "Service", "programId": "Service1", "runnableId": "Runnable1"}, {"appId": "App1", "programType": "Mapreduce", "programId": "Mapreduce2"}, {"appId": "App2", "programType": "Flow", "programId": "Flow1", "runnableId": "Flowlet1"}] </code></pre> </p><p> The response will be an array of JsonObjects each of which will contain the three input parameters as well as 3 fields: <ul> <li>"provisioned" which maps to the number of instances actually provided for the input runnable;</li> <li>"requested" which maps to the number of instances the user has requested for the input runnable; and</li> <li>"statusCode" which maps to the http status code for the data in that JsonObjects (200, 400, 404).</li> </ul> </p><p> If an error occurs in the input (for the example above, Flowlet1 does not exist), then all JsonObjects for which the parameters have a valid instances will have the provisioned and requested fields status code fields but all JsonObjects for which the parameters are not valid will have an error message and statusCode. </p><p> For example, if there is no Flowlet1 in the above data, then the response could be 200 OK with the following data: </p> <pre><code> [{"appId": "App1", "programType": "Service", "programId": "Service1", "runnableId": "Runnable1", "statusCode": 200, "provisioned": 2, "requested": 2}, {"appId": "App1", "programType": "Mapreduce", "programId": "Mapreduce2", "statusCode": 200, "provisioned": 1, "requested": 3}, {"appId": "App2", "programType": "Flow", "programId": "Flow1", "runnableId": "Flowlet1", "statusCode": 404, "error": "Program": Flowlet1 not found"}] </code></pre>
 */
@POST @Path("String_Node_Str") public void getInstances(HttpRequest request,HttpResponder responder,@PathParam("String_Node_Str") String namespaceId) throws IOException {
  try {
    List<BatchEndpointInstances> args=instancesFromBatchArgs(decodeArrayArguments(request,responder));
    if (args == null) {
      return;
    }
    for (    BatchEndpointInstances requestedObj : args) {
      Id.Application appId=Id.Application.from(namespaceId,requestedObj.getAppId());
      ApplicationSpecification spec=store.getApplication(appId);
      if (spec == null) {
        addCodeError(requestedObj,HttpResponseStatus.NOT_FOUND.getCode(),"String_Node_Str" + appId + "String_Node_Str");
        continue;
      }
      ProgramType programType=ProgramType.valueOfPrettyName(requestedObj.getProgramType());
      if (!canHaveInstances(programType)) {
        addCodeError(requestedObj,HttpResponseStatus.BAD_REQUEST.getCode(),"String_Node_Str" + programType + "String_Node_Str");
        continue;
      }
      Id.Program programId=Id.Program.from(appId,programType,requestedObj.getProgramId());
      populateProgramInstances(requestedObj,spec,programId);
    }
    responder.sendJson(HttpResponseStatus.OK,args);
  }
 catch (  SecurityException e) {
    responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
  }
catch (  JsonSyntaxException e) {
    responder.sendStatus(HttpResponseStatus.BAD_REQUEST);
  }
}