{"record":{"id":"41e4a2a7911583e4","repo":"karatelabs/karate","slug":"pattern-cannot-be-null-or-blank","errorCode":null,"errorMessage":"pattern cannot be null or blank","messagePattern":"pattern cannot be null or blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-gatling/src/main/java/io/karatelabs/gatling/KarateUriPattern.java","lineNumber":95,"sourceCode":"     *\n     * @param pattern the URI pattern (e.g., \"/users/{id}\")\n     * @return a new builder\n     */\n    public static Builder uri(String pattern) {\n        return new Builder(pattern);\n    }\n\n    /**\n     * Builder for KarateUriPattern.\n     */\n    public static final class Builder {\n\n        private final String pattern;\n        private final Map<String, Integer> methodPauses = new HashMap<>();\n\n        Builder(String pattern) {\n            if (pattern == null || pattern.isBlank()) {\n                throw new IllegalArgumentException(\"pattern cannot be null or blank\");\n            }\n            this.pattern = pattern;\n        }\n\n        /**\n         * Configure method-specific pauses for this URI pattern.\n         *\n         * @param pauses the method pause configurations\n         * @return this builder\n         */\n        public Builder pauseFor(MethodPause... pauses) {\n            for (MethodPause pause : pauses) {\n                methodPauses.put(pause.method(), pause.pauseMillis());\n            }\n            return this;\n        }\n\n        /**","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-gatling/src/main/java/io/karatelabs/gatling/KarateUriPattern.java#L77-L113","documentation":"KarateUriPattern.Builder requires the URI pattern string it is constructed with to be non-null and non-blank. The pattern defines which requests the Gatling simulation matches, so an empty pattern is meaningless and is rejected at build time with IllegalArgumentException.","triggerScenarios":"Calling new KarateUriPattern.Builder(null) or new KarateUriPattern.Builder(\"\") / new Builder(\"   \") — typically when the pattern comes from a variable, config property, or parsed string that resolved to empty.","commonSituations":"Reading the pattern from an environment variable or properties file that is unset; splitting a config string that produced an empty token; accidentally swapping constructor arguments so a null lands in the pattern slot.","solutions":["Supply the actual URI pattern string, e.g. new Builder(\"/api/v1/users/**\")","Validate/trim the config value before constructing; fail fast with a clearer message if it is blank","Check for argument-order mistakes in the Builder call"],"exampleFix":"// before\nString pattern = System.getenv(\"URI_PATTERN\"); // may be null\nnew KarateUriPattern.Builder(pattern).build();\n// after\nString pattern = Objects.requireNonNull(System.getenv(\"URI_PATTERN\"), \"URI_PATTERN not set\");\nnew KarateUriPattern.Builder(pattern).build();","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(pattern, \"URI pattern required\");\nif (pattern.isBlank()) throw new IllegalArgumentException(\"URI pattern blank\");\nnew KarateUriPattern.Builder(pattern).build();","typeGuard":null,"tryCatchPattern":"try { new KarateUriPattern.Builder(pattern).build(); } catch (IllegalArgumentException e) { log.error(\"invalid URI pattern '{}': {}\", pattern, e.getMessage()); throw e; }","preventionTips":["Load patterns from config with a default and assert non-blank at startup","Trim config strings before passing them in","Keep pattern strings as constants rather than computed values where possible"],"tags":["java","gatling","validation","blank-string"],"backgroundTag":"empty-required-field","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"}