{"record":{"id":"843cf34de3af0567","repo":"apache/hadoop","slug":"limit-value-must-be-greater-then-0","errorCode":null,"errorMessage":"limit value must be greater then 0","messagePattern":"limit value must be greater then 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":201,"sourceCode":"      @QueryParam(\"limit\") String count,\n      @QueryParam(\"state\") String stateQuery,\n      @QueryParam(\"queue\") String queueQuery,\n      @QueryParam(\"startedTimeBegin\") String startedBegin,\n      @QueryParam(\"startedTimeEnd\") String startedEnd,\n      @QueryParam(\"finishedTimeBegin\") String finishBegin,\n      @QueryParam(\"finishedTimeEnd\") String finishEnd) {\n\n    Long countParam = null;\n    init();\n    \n    if (count != null && !count.isEmpty()) {\n      try {\n        countParam = Long.parseLong(count);\n      } catch (NumberFormatException e) {\n        throw new BadRequestException(e.getMessage());\n      }\n      if (countParam <= 0) {\n        throw new BadRequestException(\"limit value must be greater then 0\");\n      }\n    }\n\n    Long sBegin = null;\n    if (startedBegin != null && !startedBegin.isEmpty()) {\n      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 {","sourceCodeStart":183,"sourceCodeEnd":219,"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#L183-L219","documentation":"The JHS REST API (HsWebServices, GET /ws/v1/history/jobs) validates the count query parameter (the result limit). A value that parses as a long but is <= 0 returns HTTP 400 with 'limit value must be greater then 0' — note the 'then' typo in the source, useful when grepping logs. Non-numeric values fail earlier with a NumberFormatException-based 400.","triggerScenarios":"GET /ws/v1/history/jobs?count=0 or any negative count; a client defaulting an unset limit to 0 instead of omitting the parameter.","commonSituations":"Client code mapping an optional 'no limit' setting to count=0; pagination math producing 0 for empty result sets; UI wiring bugs.","solutions":["Omit the count parameter entirely when no limit is wanted.","Send a positive integer (count >= 1).","Fix client code that forwards 0 or -1 as a 'no limit' sentinel."],"exampleFix":"# before\n curl 'http://jhs:19888/ws/v1/history/jobs?count=0'   # HTTP 400\n\n# after\n curl 'http://jhs:19888/ws/v1/history/jobs?count=10'  # HTTP 200\n# or omit the parameter for no limit\n curl 'http://jhs:19888/ws/v1/history/jobs'","handlingStrategy":"validation","validationCode":"function buildJobsUrl(base, { count } = {}) {\n  const params = new URLSearchParams();\n  if (count !== undefined && count !== null) {\n    const n = Number(count);\n    if (!Number.isInteger(n) || n <= 0) {\n      throw new RangeError(`count must be a positive integer, got ${count}`);\n    }\n    params.set('count', String(n));\n  }\n  return `${base}/ws/v1/history/jobs?${params.toString()}`;\n}","typeGuard":"function isPositiveInt(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  const res = await fetch(url);\n} catch { /* network only */ }\nif (res.status === 400) { /* fix the count param; do not retry unchanged */ }","preventionTips":["Omit optional limit parameters rather than sending 0.","Validate positive-integer params client-side before the request.","Map 'no limit' configs to parameter absence, not a sentinel 0."],"tags":["mapreduce","job-history-server","rest","query-params","validation"],"backgroundTag":"invalid-query-parameter","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}