{"record":{"id":"29158421b2ab3115","repo":"OpenFeign/feign","slug":"times-must-be-a-non-negative-number","errorCode":null,"errorMessage":"times must be a non negative number","messagePattern":"times must be a non negative number","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mock/src/main/java/feign/mock/MockClient.java","lineNumber":247,"sourceCode":"  public MockClient add(HttpMethod method, String url, Response response) {\n    return this.add(method, url, response.toBuilder());\n  }\n\n  public MockClient noContent(HttpMethod method, String url) {\n    return add(method, url, HttpURLConnection.HTTP_NO_CONTENT);\n  }\n\n  public Request verifyOne(HttpMethod method, String url) {\n    return verifyTimes(method, url, 1).get(0);\n  }\n\n  public Request verifyOne(RequestKey requestKey) {\n    return verifyTimes(requestKey, 1).get(0);\n  }\n\n  public List<Request> verifyTimes(final HttpMethod method, final String url, final int times) {\n    if (times < 0) {\n      throw new IllegalArgumentException(\"times must be a non negative number\");\n    }\n\n    if (times == 0) {\n      verifyNever(method, url);\n      return Collections.emptyList();\n    }\n\n    RequestKey requestKey = RequestKey.builder(method, url).build();\n    if (!requests.containsKey(requestKey)) {\n      throw new VerificationAssertionError(\n          \"Wanted: '%s' but never invoked! Got: %s\", requestKey, requests.keySet());\n    }\n\n    List<Request> result = requests.get(requestKey);\n    if (result.size() != times) {\n      throw new VerificationAssertionError(\n          \"Wanted: '%s' to be invoked: '%s' times but got: '%s'!\",\n          requestKey, times, result.size());","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/mock/src/main/java/feign/mock/MockClient.java#L229-L265","documentation":"verifyTimes(HttpMethod, String, int) validates its times argument before running any verification. A negative count is meaningless, so an IllegalArgumentException is thrown. It is an immediate programmer-input validation error, not a verification failure.","triggerScenarios":"Calling mockClient.verifyTimes(method, url, -1) (or any negative int), directly or via verifyOne with a computed negative count.","commonSituations":"times computed from a loop counter or a size calculation that went negative; copy-paste of -1 sentinel value; test parameterized with bad input.","solutions":["Pass a non-negative times value (0 means verifyNever)","Guard computed values: times = Math.max(0, expectedCount) before calling","If you intend 'never invoked', call verifyNever(method, url) or pass 0"],"exampleFix":"// before\nmockClient.verifyTimes(HttpMethod.GET, \"/users\", -1);\n// after\nmockClient.verifyTimes(HttpMethod.GET, \"/users\", 0); // or verifyNever","handlingStrategy":"validation","validationCode":"if (times < 0) {\n  throw new IllegalArgumentException(\"times must be >= 0 before calling verifyTimes\");\n}\nmockClient.verifyTimes(method, url, times);","typeGuard":null,"tryCatchPattern":"try {\n  mockClient.verifyTimes(method, url, times);\n} catch (IllegalArgumentException e) {\n  fail(\"Bad test input for verifyTimes: \" + e.getMessage());\n}","preventionTips":["Never hardcode negative counts; use 0 for 'never'","Clamp computed counters with Math.max(0, n)"],"tags":["mock","test","verification","illegal-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}