elastic/elasticsearch · error · IllegalArgumentException
pathPrefix is malformed. consecutive slashes are not allowed
Error message
pathPrefix is malformed. consecutive slashes are not allowed: [{}] What it means
Validation in cleanPathPrefix: the prefix must not contain consecutive slashes ("//"). Such input would silently collapse or produce wrong paths, so it is rejected outright rather than normalized.
Source
Thrown at client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java:220
* it is not intended for other purposes and it should not be supplied in other scenarios.
*
* @throws NullPointerException if {@code pathPrefix} is {@code null}.
* @throws IllegalArgumentException if {@code pathPrefix} is empty or contains consecutive slashes.
*/
public RestClientBuilder setPathPrefix(String pathPrefix) {
this.pathPrefix = cleanPathPrefix(pathPrefix);
return this;
}
public static String cleanPathPrefix(String pathPrefix) {
Objects.requireNonNull(pathPrefix, "pathPrefix must not be null");
if (pathPrefix.isEmpty()) {
throw new IllegalArgumentException("pathPrefix must not be empty");
}
if (pathPrefix.contains("//")) {
throw new IllegalArgumentException("pathPrefix is malformed. consecutive slashes are not allowed: [" + pathPrefix + "]");
}
String cleanPathPrefix = pathPrefix;
if (cleanPathPrefix.startsWith("/") == false) {
cleanPathPrefix = "/" + cleanPathPrefix;
}
// best effort to ensure that it looks like "/base/path" rather than "/base/path/"
if (cleanPathPrefix.endsWith("/") && cleanPathPrefix.length() > 1) {
cleanPathPrefix = cleanPathPrefix.substring(0, cleanPathPrefix.length() - 1);
}
return cleanPathPrefix;
}
/**
* Sets the {@link NodeSelector} to be used for all requests.
* @throws NullPointerException if the provided nodeSelector is null
*/View on GitHub (pinned to db6a809a66)
Solutions
- Build the prefix from segments joined by a single slash, or collapse '//' to '/' yourself before passing.
- Strip trailing slashes from each config segment before joining.
- Run a quick sanity check: prefix.indexOf("//") < 0.
Example fix
// before
builder.setPathPrefix(base + "/" + sub); // base ends with '/', sub starts with '/'
// after
String joined = (base + "/" + sub).replaceAll("/+", "/");
builder.setPathPrefix(joined); Defensive patterns
Strategy: validation
Validate before calling
String p = prefix.trim().replaceAll("/+", "/");
if (!p.isEmpty() && !p.contains("//")) builder.setPathPrefix(p); Type guard
prefix == null || (!prefix.isEmpty() && !prefix.contains("//")) Prevention
- Always join path segments with a single slash.
- Collapse accidental doubles before passing to the builder.
When it happens
Trigger: Calling setPathPrefix("/base//path") or any prefix where a user joined segments with extra slashes.
Common situations: Concatenating "base/" + "/sub" from config fields; copy-paste of a URL path with double slash; trailing-slash handling code that prepended a slash twice.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- pathPrefix must not be empty
- hosts must not be null nor empty
- nodes must not be null or empty
- node cannot be null
- can't compare DeadHostStates holding different time supplier
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/7eb5d12f5840119c.
Report an issue: GitHub.