karatelabs/karate · error · IllegalArgumentException

method cannot be null or blank

Error message

method cannot be null or blank

What it means

MethodPause is a compact-constructor record validating that the HTTP method is non-null, non-blank, and that the pause is non-negative, then normalizes the method to uppercase. A null/blank method throws IllegalArgumentException immediately at record creation.

Solutions

  1. Pass a concrete method name such as "GET", "POST", "PUT","DELETE"
  2. Trim/validate the method string before constructing the record
  3. If parsing config, skip entries with blank methods instead of constructing them

Example fix

// before
String m = parts.length > 0 ? parts[0] : "";
new MethodPause(m, pauseMs); // throws when m is blank
// after
if (parts.length > 0 && !parts[0].isBlank()) {
    new MethodPause(parts[0], pauseMs);
}
Defensive patterns

Strategy: validation

Validate before calling

if (method == null || method.isBlank()) throw new IllegalArgumentException("method required");
new MethodPause(method, pauseMillis);

Try / catch

try { return new MethodPause(method, pauseMillis); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("bad method pause for '" + method + "': " + e.getMessage(), e); }

Prevention

When it happens

Trigger: new MethodPause(null, 500) or new MethodPause(" ", 500); typically when the method string comes from a parsed map key, split token, or optional config.

Common situations: Building method pauses from a config map where an entry has a missing/empty key; parsing strings like ":500" where the method part is empty; case mistakes are fine (normalized) but blank input is not.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/ac5eae2b4d75097c. Report an issue: GitHub.

Appendix: source

Thrown at karate-gatling/src/main/java/io/karatelabs/gatling/MethodPause.java:37

 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package io.karatelabs.gatling;

/**
 * Represents a pause duration for a specific HTTP method.
 * Used with URI patterns to define method-specific pauses after requests.
 *
 * @param method the HTTP method (GET, POST, etc.)
 * @param pauseMillis the pause duration in milliseconds
 */
public record MethodPause(String method, int pauseMillis) {

    public MethodPause {
        if (method == null || method.isBlank()) {
            throw new IllegalArgumentException("method cannot be null or blank");
        }
        if (pauseMillis < 0) {
            throw new IllegalArgumentException("pauseMillis cannot be negative");
        }
        method = method.toUpperCase();
    }

}

View on GitHub (pinned to a22eb90246)