redis/jedis · error · JedisValidationException
client info cannot contain spaces, newlines or special…
Error message
client info cannot contain spaces, newlines or special characters.
What it means
validateClientInfo() enforces that every character of the CLIENT SETINFO/setName value is a printable ASCII character ('!' through '~'). Spaces, newlines, and other special characters would corrupt the client-info string on the server, so JedisValidationException is thrown.
Solutions
- Sanitize the string: replace all chars outside [!-~] with a safe substitute (e.g. '_') before calling
- Validate with a regex like [!-~]+ and reject/transform invalid input early
- Encode metadata as a single token, e.g. 'my_app_dev' instead of 'my app (dev)'
Example fix
// before
connection.setClientInfo(appName + " " + env); // contains space
// after
String info = (appName + "_" + env).replaceAll("[^!-~]", "_");
connection.setClientInfo(info); Defensive patterns
Strategy: validation
Validate before calling
static final Pattern SAFE = Pattern.compile("[!-~]+");
if (!SAFE.matcher(info).matches()) throw new IllegalArgumentException("client info must be printable ASCII without spaces"); Type guard
static boolean isSafeClientInfo(String s) { return s != null && s.chars().allMatch(c -> c >= '!' && c <= '~'); } Try / catch
try { conn.setClientInfo(info); } catch (JedisValidationException e) { log.warn("invalid client info rejected: " + info); } Prevention
- Sanitize labels derived from process/thread/user input
- Use '_' instead of spaces in client info
- Validate at config time, not at connect time
When it happens
Trigger: Calling connection.setClientInfo(...) or client-name APIs with values containing spaces, tabs, CR/LF, or non-ASCII characters (e.g. hostnames with dots are fine, but 'my app (dev)' is not).
Common situations: Deriving client info from process names, thread names, or user-supplied labels that contain spaces; encoding app metadata with separators like '|' or ' '; forgetting to sanitize before set.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- DriverInfo must not be null
- DIALECT=0 cannot be set.
- failed to connect. Please check configuration and try again.
- Provided endpoint is null. Please use one from the…
- Provided endpoint: is not within the configured endpoints…
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/66d45f9d385178b7.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/Connection.java:840
responses.add(readProtocolWithCheckingBroken());
} catch (JedisDataException e) {
responses.add(e);
}
}
return responses;
}
/**
* Check if the client name libname, libver, characters are legal
* @param info the name
* @return Returns true if legal, false throws exception
* @throws JedisException if characters illegal
*/
private static boolean validateClientInfo(String info) {
for (int i = 0; i < info.length(); i++) {
char c = info.charAt(i);
if (c < '!' || c > '~') {
throw new JedisValidationException(
"client info cannot contain spaces, " + "newlines or special characters.");
}
}
return true;
}
/**
* Initialize this connection using the {@link JedisClientConfig} captured at construction.
* <p>
* Internal lifecycle step: invoked once by {@link Connection.Builder#build()} for direct
* callers, and once by {@link ConnectionFactory#initialize(Connection)} for pooled
* connections. There is no public construction path that produces an uninitialized-but-
* configured {@code Connection}, so this method has no out-of-package use case.
*/
void initializeFromClientConfig() {
this.initializeFromClientConfig(clientConfig);
}
View on GitHub (pinned to 6dac31d4c2)