{"record":{"id":"dd02161bc94a5dcf","repo":"apache/druid","slug":"limit-must-be-greater-than-zero","errorCode":null,"errorMessage":"Limit must be greater than zero!","messagePattern":"Limit must be greater than zero!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server/src/main/java/org/apache/druid/server/audit/SQLAuditManager.java","lineNumber":197,"sourceCode":"            .map(resultMapper)\n            .list()\n    );\n  }\n\n  private Interval createAuditHistoryIntervalIfNull(Interval interval)\n  {\n    if (interval == null) {\n      DateTime now = DateTimes.nowUtc();\n      return new Interval(now.minus(config.getAuditHistoryMillis()), now);\n    } else {\n      return interval;\n    }\n  }\n\n  private int getLimit(int limit) throws IllegalArgumentException\n  {\n    if (limit < 1) {\n      throw new IllegalArgumentException(\"Limit must be greater than zero!\");\n    }\n    return limit;\n  }\n\n  @Override\n  public List<AuditEntry> fetchAuditHistory(final String type, Interval interval)\n  {\n    final Interval theInterval = createAuditHistoryIntervalIfNull(interval);\n    return dbi.withHandle(\n        (Handle handle) -> handle\n            .createQuery(\n                StringUtils.format(\n                    \"SELECT payload FROM %s WHERE type = :type and created_date between :start_date and \"\n                    + \":end_date ORDER BY created_date\",\n                    getAuditTable()\n                )\n            )\n            .bind(\"type\", type)","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/server/audit/SQLAuditManager.java#L179-L215","documentation":"SQLAuditManager.fetchAuditHistory validates the requested limit for how many audit entries to return. If the caller passes a limit less than 1, getLimit throws this IllegalArgumentException immediately. The limit must be a positive integer because it is used as a page/row count in the database query.","triggerScenarios":"Calling fetchAuditHistory(type, interval, limit) with limit == 0 or any negative number, e.g. a client query string like ?limit=0 or a deserialized/default limit of 0.","commonSituations":"API clients passing 0 to mean 'unlimited' (this API does not support that convention); frontend code defaulting a missing limit parameter to 0 instead of a positive value; automated scripts constructing the request with an unset variable.","solutions":["Pass a limit >= 1 in the audit history request (e.g. ?limit=25).","If 'no limit' is intended, omit the limit parameter if the API supports a null/default, or pass a large value like 10000.","Fix client code that defaults a missing query parameter to 0; default to a positive constant instead."],"exampleFix":"// before\nString limitParam = req.getParameter(\"limit\");\nint limit = limitParam == null ? 0 : Integer.parseInt(limitParam);\nauditManager.fetchAuditHistory(type, interval, limit);\n// after\nint limit = limitParam == null ? 25 : Math.max(1, Integer.parseInt(limitParam));\nauditManager.fetchAuditHistory(type, interval, limit);","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(limit) || limit < 1) {\n  throw new RangeError(`limit must be a positive integer, got ${limit}`);\n}\nauditManager.fetchAuditHistory(type, interval, limit);","typeGuard":"function isValidLimit(limit) {\n  return Number.isInteger(limit) && limit >= 1;\n}","tryCatchPattern":"try {\n  entries = auditManager.fetchAuditHistory(type, interval, limit);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Limit must be greater than zero\")) {\n    entries = auditManager.fetchAuditHistory(type, interval, 25);\n  } else { throw e; }\n}","preventionTips":["Never use 0 to mean 'unlimited' with Druid audit APIs; omit or use a large positive value.","Clamp client-supplied limits with Math.max(1, limit) before sending requests."],"tags":["validation","audit","rest-api","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}