karatelabs/karate · error · IllegalArgumentException
pattern cannot be null or blank
Error message
pattern cannot be null or blank
What it means
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.
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
Example fix
// before
String pattern = System.getenv("URI_PATTERN"); // may be null
new KarateUriPattern.Builder(pattern).build();
// after
String pattern = Objects.requireNonNull(System.getenv("URI_PATTERN"), "URI_PATTERN not set");
new KarateUriPattern.Builder(pattern).build(); Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(pattern, "URI pattern required");
if (pattern.isBlank()) throw new IllegalArgumentException("URI pattern blank");
new KarateUriPattern.Builder(pattern).build(); Try / catch
try { new KarateUriPattern.Builder(pattern).build(); } catch (IllegalArgumentException e) { log.error("invalid URI pattern '{}': {}", pattern, e.getMessage()); throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- method cannot be null or blank
- pauseMillis cannot be negative
- valueSupplier cannot be null
- cannot replace root path $
- configure logging.mask: unknown key
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/41e4a2a7911583e4.
Report an issue: GitHub.
Appendix: source
Thrown at karate-gatling/src/main/java/io/karatelabs/gatling/KarateUriPattern.java:95
*
* @param pattern the URI pattern (e.g., "/users/{id}")
* @return a new builder
*/
public static Builder uri(String pattern) {
return new Builder(pattern);
}
/**
* Builder for KarateUriPattern.
*/
public static final class Builder {
private final String pattern;
private final Map<String, Integer> methodPauses = new HashMap<>();
Builder(String pattern) {
if (pattern == null || pattern.isBlank()) {
throw new IllegalArgumentException("pattern cannot be null or blank");
}
this.pattern = pattern;
}
/**
* Configure method-specific pauses for this URI pattern.
*
* @param pauses the method pause configurations
* @return this builder
*/
public Builder pauseFor(MethodPause... pauses) {
for (MethodPause pause : pauses) {
methodPauses.put(pause.method(), pause.pauseMillis());
}
return this;
}
/**View on GitHub (pinned to a22eb90246)