{"record":{"id":"8532085aadf34b4e","repo":"karatelabs/karate","slug":"pausemillis-cannot-be-negative","errorCode":null,"errorMessage":"pauseMillis cannot be negative","messagePattern":"pauseMillis cannot be negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-gatling/src/main/java/io/karatelabs/gatling/MethodPause.java","lineNumber":40,"sourceCode":" * THE SOFTWARE.\n */\npackage io.karatelabs.gatling;\n\n/**\n * Represents a pause duration for a specific HTTP method.\n * Used with URI patterns to define method-specific pauses after requests.\n *\n * @param method the HTTP method (GET, POST, etc.)\n * @param pauseMillis the pause duration in milliseconds\n */\npublic record MethodPause(String method, int pauseMillis) {\n\n    public MethodPause {\n        if (method == null || method.isBlank()) {\n            throw new IllegalArgumentException(\"method cannot be null or blank\");\n        }\n        if (pauseMillis < 0) {\n            throw new IllegalArgumentException(\"pauseMillis cannot be negative\");\n        }\n        method = method.toUpperCase();\n    }\n\n}\n","sourceCodeStart":22,"sourceCodeEnd":46,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-gatling/src/main/java/io/karatelabs/gatling/MethodPause.java#L22-L46","documentation":"Record constructor invariant for MethodPause: a pause duration only makes sense as zero or positive milliseconds. Fires when a negative pauseMillis is passed to the compact constructor; pass 0 or a positive value.","triggerScenarios":"new MethodPause(\"GET\", -100) — usually from arithmetic like (target - current) that went negative, or a config value entered as a negative number, or subtracting timestamps in the wrong order.","commonSituations":"Computing randomized pauses where a max below the min yields a negative delta; mis-typed config values in pause tuning; timezone/clock-order bugs when deriving pauses from measured times.","solutions":["Use 0 or a positive value for pauseMillis","Clamp computed values: Math.max(0, computedPause)","Fix the min/max order in any randomization code (e.g. use between(min, max) with min <= max)"],"exampleFix":"// before\nlong pause = target - current; // can be negative\nnew MethodPause(\"GET\", (int) pause);\n// after\nlong pause = Math.max(0, target - current);\nnew MethodPause(\"GET\", (int) pause);","handlingStrategy":"validation","validationCode":"if (pauseMillis < 0) throw new IllegalArgumentException(\"pauseMillis must be >= 0\");\nnew MethodPause(method, pauseMillis);","typeGuard":null,"tryCatchPattern":"try { return new MethodPause(method, pauseMillis); } catch (IllegalArgumentException e) { log.warn(\"rejecting negative pause {}: using 0\", pauseMillis); return new MethodPause(method, 0); }","preventionTips":["Clamp computed pauses with Math.max(0, value)","Double-check min/max argument order in randomization helpers","Never hand-enter negative durations in pause config"],"tags":["java","record","validation","argument-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}