{"record":{"id":"6dea70b1843eafeb","repo":"apache/hadoop","slug":"task-attempt-id-not-found-or-invalid","errorCode":null,"errorMessage":"task attempt id {} not found or invalid","messagePattern":"task attempt id (.+?) not found or invalid","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"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":215,"sourceCode":"    TaskAttemptId attemptId;\n    TaskAttempt ta;\n    try {\n      attemptId = MRApps.toTaskAttemptID(attId);\n    } catch (YarnRuntimeException e) {\n      // TODO: after MAPREDUCE-2793 YarnRuntimeException is probably not expected here\n      // anymore but keeping it for now just in case other stuff starts failing.\n      // Also, the webservice should ideally return BadRequest (HTTP:400) when\n      // the id is malformed instead of NotFound (HTTP:404). The webserver on\n      // top of which AMWebServices is built seems to automatically do that for\n      // unhandled exceptions\n      throw new NotFoundException(e.getMessage());\n    } catch (NumberFormatException ne) {\n      throw new NotFoundException(ne.getMessage());\n    } catch (IllegalArgumentException e) {\n      throw new NotFoundException(e.getMessage());\n    }\n    if (attemptId == null) {\n      throw new NotFoundException(\"task attempt id \" + attId\n          + \" not found or invalid\");\n    }\n    ta = task.getAttempt(attemptId);\n    if (ta == null) {\n      throw new NotFoundException(\"Error getting info on task attempt id \"\n          + attId);\n    }\n    return ta;\n  }\n\n\n  /**\n   * check for job access.\n   *\n   * @param job\n   *          the job that is being accessed\n   */\n  void checkAccess(Job job, HttpServletRequest request) {","sourceCodeStart":197,"sourceCodeEnd":233,"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#L197-L233","documentation":"AMWebServices.getTaskAttemptFromTaskAttemptString converts the {attemptid} path parameter with MRApps.toTaskAttemptID(); the call returned null (null/empty input or missing 'attempt_' prefix) instead of throwing, so the AM REST API fails the request with HTTP 404 'task attempt id ... not found or invalid'. Malformed ids are reported as 404, not 400 (see the comment at AMWebServices.java:204-207).","triggerScenarios":"Any /ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts/{attemptid}... endpoint (info, counters, PUT state) where attemptid lacks the 'attempt_' prefix - e.g. a bare task id 'task_1401..._m_000005' - or is null/empty.","commonSituations":"A task id is used where the attempt id is expected; the trailing attempt number is dropped (attempt_..._000005 instead of attempt_..._000005_0); long ids truncated in logs, terminals, or templating systems.","solutions":["Use an attempt id exactly as returned by GET .../tasks/{taskid}/attempts","Check the format: attempt_<jobTimestamp>_<jobSeq>_[m|r]_<taskSeq>_<attemptSeq>, e.g. attempt_1401318629735_0001_m_000005_0","Trim and URL-encode the parameter; ensure no prefix other than 'attempt_'"],"exampleFix":"// before\nGET .../jobs/job_1_0001/tasks/task_1_0001_m_000005/attempts/task_1_0001_m_000005\n// 404 { \"task attempt id task_1_0001_m_000005 not found or invalid\" }\n\n// after\nGET .../jobs/job_1_0001/tasks/task_1_0001_m_000005/attempts/attempt_1_0001_m_000005_0","handlingStrategy":"validation","validationCode":"private static final Pattern ATTEMPT_ID_RE =\n    Pattern.compile(\"^attempt_\\\\d+_\\\\d+_[mr]_\\\\d+_\\\\d+$\");\n\nif (attId == null || !ATTEMPT_ID_RE.matcher(attId).matches()) {\n  throw new IllegalArgumentException(\"bad attempt id: \" + attId);\n}","typeGuard":"static boolean isWellFormedAttemptId(String attId) {\n  return attId != null && attId.startsWith(\"attempt_\")\n      && attId.split(\"_\").length == 6;\n}","tryCatchPattern":"try {\n  AttemptInfo a = client.target(amBase)\n      .path(\"jobs/{jid}/tasks/{tid}/attempts/{aid}\")\n      .resolveTemplates(Map.of(\"jid\", jid, \"tid\", tid, \"aid\", attId))\n      .request(MediaType.APPLICATION_JSON).get(AttemptInfo.class);\n} catch (javax.ws.rs.NotFoundException nfe) {\n  // malformed or unknown attempt id\n}","preventionTips":["Take attempt ids from GET .../tasks/{taskid}/attempts listings","Remember the shape: attempt_<job>_[m|r]_<task>_<attemptNo> - one extra segment beyond a task id","Never substitute a task id where an attempt id is required"],"tags":["mapreduce","rest","http-404","applicationmaster","task-attempt-id"],"backgroundTag":"rest-malformed-resource-id","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}