redis/jedis · error · JedisValidationException

must not contain spaces, newlines, non-printable…

Error message

 must not contain spaces, newlines, non-printable characters, or braces

What it means

DriverInfo.validateNoInvalidCharacters throws JedisValidationException when a driver name or version contains any character outside printable ASCII '!'..'~' or contains braces ({ or }). Spaces, newlines, tabs, control characters, and non-ASCII characters are all rejected because CLIENT SETINFO lib entries must be single printable tokens.

Solutions

  1. Sanitize the value: strip or replace spaces, newlines, and braces, e.g. value.replaceAll("[^!-~]|[{}],", "")-style filtering keeping only printable non-brace ASCII.
  2. Use a compact identifier such as "my-driver" and "1.0.0-beta1" instead of free-form text.
  3. Validate caller-side with a regex like ^[!-~&&[^{}]]+$ before calling addUpstreamDriver.

Example fix

// before
builder.addUpstreamDriver("My Cool Driver", version); // spaces rejected
// after
String safe = version == null ? "unknown" : version.replaceAll("[^\\x21-\\x7E]", "").replace("{", "").replace("}", "");
builder.addUpstreamDriver("MyCoolDriver", safe);
Defensive patterns

Strategy: validation

Validate before calling

static boolean isValidDriverField(String s) {
  if (s == null) return false;
  for (char c : s.toCharArray()) {
    if (c < '!' || c > '~' || c == '{' || c == '}') return false;
  }
  return !s.isEmpty();
}

Try / catch

try {
  builder.addUpstreamDriver(name, version);
} catch (JedisValidationException e) {
  log.warn("Driver field has invalid characters: {}", e.getMessage());
}

Prevention

When it happens

Trigger: addUpstreamDriver("my driver", "1.0") (space in name); addUpstreamDriver("driver", "1.0\n"); versions containing "{"/"}"; names with UTF-8 or emoji characters; values copied with trailing whitespace or BOM.

Common situations: Versions like "1.0 (build 42)" containing spaces/parens are fine but "1.0 beta" is not; branding names with curly braces or unicode; values read from Windows files with CRLF endings; templates injecting values with newlines.

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


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/c96dbbcd7f8f1313. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/DriverInfo.java:244

    validateNoInvalidCharacters(value, fieldName);
  }

  /**
   * Validates that the value does not contain characters that would violate the format of the Redis
   * CLIENT LIST reply: non-printable characters, spaces, or brace characters.
   * <p>
   * Only printable ASCII characters (0x21-0x7E, i.e., '!' to '~') are allowed, excluding braces.
   * @param value the value to validate
   * @param fieldName the name of the field for error messages
   * @throws JedisValidationException if the value contains invalid characters
   * @see <a href="https://redis.io/docs/latest/commands/client-setinfo/">CLIENT SETINFO</a>
   */
  private static void validateNoInvalidCharacters(String value, String fieldName) {
    for (int i = 0; i < value.length(); i++) {
      char c = value.charAt(i);
      if (c < '!' || c > '~' || BRACES.contains(c)) {
        throw new JedisValidationException(
            fieldName + " must not contain spaces, newlines, non-printable characters, or braces");
      }
    }
  }

  private static String formatDriverInfo(String driverName, String driverVersion) {
    return driverName + "_v" + driverVersion;
  }
}

View on GitHub (pinned to 6dac31d4c2)