{"record":{"id":"3a17148d679c50f7","repo":"apache/hadoop","slug":"tasktype-must-be-either-m-or-r","errorCode":null,"errorMessage":"tasktype must be either m or r","messagePattern":"tasktype must be either m or r","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebServices.java","lineNumber":358,"sourceCode":"\n  @GET\n  @Path(\"/jobs/{jobid}/tasks\")\n  @Produces({ MediaType.APPLICATION_JSON + \"; \" + JettyUtils.UTF_8,\n      MediaType.APPLICATION_XML + \"; \" + JettyUtils.UTF_8 })\n  public TasksInfo getJobTasks(@Context HttpServletRequest hsr,\n      @PathParam(\"jobid\") String jid, @QueryParam(\"type\") String type) {\n\n    init();\n    Job job = getJobFromJobIdString(jid, appCtx);\n    checkAccess(job, hsr);\n    TasksInfo allTasks = new TasksInfo();\n    for (Task task : job.getTasks().values()) {\n      TaskType ttype = null;\n      if (type != null && !type.isEmpty()) {\n        try {\n          ttype = MRApps.taskType(type);\n        } catch (YarnRuntimeException e) {\n          throw new BadRequestException(\"tasktype must be either m or r\");\n        }\n      }\n      if (ttype != null && task.getType() != ttype) {\n        continue;\n      }\n      allTasks.add(new TaskInfo(task));\n    }\n    return allTasks;\n  }\n\n  @GET\n  @Path(\"/jobs/{jobid}/tasks/{taskid}\")\n  @Produces({ MediaType.APPLICATION_JSON + \"; \" + JettyUtils.UTF_8,\n      MediaType.APPLICATION_XML + \"; \" + JettyUtils.UTF_8 })\n  public TaskInfo getJobTask(@Context HttpServletRequest hsr,\n      @PathParam(\"jobid\") String jid, @PathParam(\"taskid\") String tid) {\n\n    init();","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebServices.java#L340-L376","documentation":"getJobTasks maps the optional 'type' query parameter through MRApps.taskType(), which accepts exactly 'm' or 'r' (lowercase, MRApps.java:154-159). Any other non-empty value throws YarnRuntimeException inside, rethrown as a JAX-RS BadRequestException - HTTP 400 'tasktype must be either m or r'.","triggerScenarios":"GET /ws/v1/mapreduce/jobs/{jobid}/tasks?type=map, ?type=REDUCE, ?type=maps - any value other than 'm' or 'r'. Omitting 'type' (or sending an empty value) is valid and returns all tasks.","commonSituations":"Clients reuse human-readable words ('map', 'reduce') from the UI or old JobConf vocabulary instead of the REST symbols; uppercase input; trailing whitespace or encoding artifacts.","solutions":["Use type=m for map tasks and type=r for reduce tasks","Omit the parameter entirely to list all tasks","Normalize external input to a lowercase single letter before calling"],"exampleFix":"// before\nGET /ws/v1/mapreduce/jobs/job_1_0001/tasks?type=map\n// 400 { \"tasktype must be either m or r\" }\n\n// after\nGET /ws/v1/mapreduce/jobs/job_1_0001/tasks?type=m","handlingStrategy":"validation","validationCode":"Set<String> VALID = Set.of(\"m\", \"r\");\nif (type != null && !VALID.contains(type)) {\n  throw new IllegalArgumentException(\"type must be 'm' or 'r'\");\n}\n// then: .queryParam(\"type\", type)","typeGuard":"static boolean isValidTaskTypeFilter(String type) {\n  return type == null || type.equals(\"m\") || type.equals(\"r\");\n}","tryCatchPattern":"try {\n  return listTasks(jid, type);\n} catch (javax.ws.rs.BadRequestException bre) {\n  if (bre.getMessage().contains(\"tasktype\")) {\n    return listTasks(jid, null); // retry without the filter\n  }\n  throw bre;\n}","preventionTips":["Whitelist 'm' and 'r' at the client boundary; reject anything else before the request","Lowercase external input before using it as the filter","Omit the parameter to get all tasks when the caller's intent is unclear"],"tags":["mapreduce","rest","http-400","query-parameter","task-type"],"backgroundTag":"invalid-query-parameter-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}