{"record":{"id":"57a29073b314642e","repo":"apache/hadoop","slug":"tasktype-must-be-either-m-or-r-57a290","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":"warning","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsWebServices.java","lineNumber":350,"sourceCode":"\n  @GET\n  @Path(\"/mapreduce/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 = AMWebServices.getJobFromJobIdString(jid, ctx);\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(\"/mapreduce/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":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsWebServices.java#L332-L368","documentation":"Thrown by the JobHistoryServer REST endpoint GET /ws/v1/history/mapreduce/jobs/{jobid}/tasks?type=... when the type value is not exactly 'm' or 'r'. The handler calls MRApps.taskType(type), which only maps the single-character symbols 'm' (map) and 'r' (reduce) and throws YarnRuntimeException for anything else; HsWebServices converts that to a BadRequestException (HTTP 400).","triggerScenarios":"GET /ws/v1/history/mapreduce/jobs/{jobid}/tasks?type=map, type=MAP, type=reduce, type=mapper, or any string other than exactly 'm' or 'r'. An empty value is treated as 'no filter' and does not trigger this.","commonSituations":"Passing the full word because the same API family (AM web services) documents type as m|r but users assume words; Case mismatch: 'M'/'R' are rejected — the check is case-sensitive; Scripts templating type=${TASK_KIND} where TASK_KIND is 'map' from other tooling","solutions":["Use exactly type=m or type=r (lowercase single character)","Omit the type parameter to list all tasks of both kinds","Map friendly names to symbols before building the URL"],"exampleFix":"# before\ncurl \"http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks?type=map\"\n\n# after\ncurl \"http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks?type=m\"","handlingStrategy":"validation","validationCode":"static String taskTypeSymbol(String input) {\n  if (input == null || input.isEmpty()) return null;      // no filter\n  if (input.equalsIgnoreCase(\"m\") || input.equalsIgnoreCase(\"map\"))  return \"m\";\n  if (input.equalsIgnoreCase(\"r\") || input.equalsIgnoreCase(\"reduce\")) return \"r\";\n  throw new IllegalArgumentException(\"type must be m or r: \" + input);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map user-facing words (map/reduce) to m/r in one helper used by every call site","The check is case- and spelling-exact: 'M', 'MAP', 'mapper' all fail","Omit type to get both task kinds, then filter client-side if unsure"],"tags":["hadoop","mapreduce","jobhistory","rest","http-400","enum-value","task-type"],"backgroundTag":"invalid-enum-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}