{"record":{"id":"92c9a207dd2fbc39","repo":"apache/hadoop","slug":"startedtimeend-must-be-greater-than-0","errorCode":null,"errorMessage":"startedTimeEnd must be greater than 0","messagePattern":"startedTimeEnd must be greater than 0","errorType":"validation","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":225,"sourceCode":"      try {\n        sBegin = Long.parseLong(startedBegin);\n      } catch (NumberFormatException e) {\n        throw new BadRequestException(\"Invalid number format: \" + e.getMessage());\n      }\n      if (sBegin < 0) {\n        throw new BadRequestException(\"startedTimeBegin must be greater than 0\");\n      }\n    }\n    \n    Long sEnd = null;\n    if (startedEnd != null && !startedEnd.isEmpty()) {\n      try {\n        sEnd = Long.parseLong(startedEnd);\n      } catch (NumberFormatException e) {\n        throw new BadRequestException(\"Invalid number format: \" + e.getMessage());\n      }\n      if (sEnd < 0) {\n        throw new BadRequestException(\"startedTimeEnd must be greater than 0\");\n      }\n    }\n    if (sBegin != null && sEnd != null && sBegin > sEnd) {\n      throw new BadRequestException(\n          \"startedTimeEnd must be greater than startTimeBegin\");\n    }\n\n    Long fBegin = null;\n    if (finishBegin != null && !finishBegin.isEmpty()) {\n      try {\n        fBegin = Long.parseLong(finishBegin);\n      } catch (NumberFormatException e) {\n        throw new BadRequestException(\"Invalid number format: \" + e.getMessage());\n      }\n      if (fBegin < 0) {\n        throw new BadRequestException(\"finishedTimeBegin must be greater than 0\");\n      }\n    }","sourceCodeStart":207,"sourceCodeEnd":243,"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#L207-L243","documentation":"Thrown by the JobHistoryServer REST API (HsWebServices.getJobs) when the startedTimeEnd query parameter of GET /ws/v1/history/mapreduce/jobs parses to a negative long. The endpoint validates the epoch-milliseconds window for filtering jobs by start time and rejects negative bounds with a JAX-RS BadRequestException, which surfaces as HTTP 400. Despite the wording, the code only rejects values < 0 (sEnd < 0), so 0 itself is accepted.","triggerScenarios":"Calling GET /ws/v1/history/mapreduce/jobs?startedTimeEnd=-1 (or any negative number). The parameter must be absent, empty, or a non-negative epoch-milliseconds long.","commonSituations":"Computing end = begin - window instead of begin + window when building a time window client-side; Passing a sentinel like -1 to mean 'no bound' instead of omitting the parameter; Clock/sign arithmetic bugs when converting human-readable dates to epoch millis","solutions":["Pass startedTimeEnd as a non-negative epoch-milliseconds value (e.g. System.currentTimeMillis())","If no end bound is wanted, omit the startedTimeEnd parameter entirely rather than sending -1","Double-check client-side window math: startedTimeBegin <= startedTimeEnd, both >= 0"],"exampleFix":"// before\nlong end = begin - 3600_000; // sign error -> negative\ncurl \"http://jhs:19888/ws/v1/history/mapreduce/jobs?startedTimeBegin=$begin&startedTimeEnd=$end\"\n\n// after\nlong end = begin + 3600_000; // 1h window, non-negative\n// or omit startedTimeEnd when unbounded","handlingStrategy":"validation","validationCode":"long end = ...;\nif (end < 0) end = System.currentTimeMillis(); // clamp, or drop param\nMap<String,String> q = new LinkedHashMap<>();\nif (end >= 0) q.put(\"startedTimeEnd\", Long.toString(end));\n// build URL only from sanitized q","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat optional numeric REST params as absent-by-default; never send sentinel values like -1","Centralize epoch-millis computation in one client helper so sign/window bugs surface once","Log the exact query string on any 400 to make parameter mistakes obvious"],"tags":["hadoop","mapreduce","jobhistory","rest","http-400","query-param","time-range"],"backgroundTag":"query-param-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}