{"record":{"id":"66d45f9d385178b7","repo":"redis/jedis","slug":"client-info-cannot-contain-spaces-newlines-or-spe","errorCode":null,"errorMessage":"client info cannot contain spaces, newlines or special characters.","messagePattern":"client info cannot contain spaces, newlines or special characters\\.","errorType":"validation","errorClass":"JedisValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/Connection.java","lineNumber":840,"sourceCode":"        responses.add(readProtocolWithCheckingBroken());\n      } catch (JedisDataException e) {\n        responses.add(e);\n      }\n    }\n    return responses;\n  }\n\n  /**\n   * Check if the client name libname, libver, characters are legal\n   * @param info the name\n   * @return Returns true if legal, false throws exception\n   * @throws JedisException if characters illegal\n   */\n  private static boolean validateClientInfo(String info) {\n    for (int i = 0; i < info.length(); i++) {\n      char c = info.charAt(i);\n      if (c < '!' || c > '~') {\n        throw new JedisValidationException(\n            \"client info cannot contain spaces, \" + \"newlines or special characters.\");\n      }\n    }\n    return true;\n  }\n\n  /**\n   * Initialize this connection using the {@link JedisClientConfig} captured at construction.\n   * <p>\n   * Internal lifecycle step: invoked once by {@link Connection.Builder#build()} for direct\n   * callers, and once by {@link ConnectionFactory#initialize(Connection)} for pooled\n   * connections. There is no public construction path that produces an uninitialized-but-\n   * configured {@code Connection}, so this method has no out-of-package use case.\n   */\n  void initializeFromClientConfig() {\n    this.initializeFromClientConfig(clientConfig);\n  }\n","sourceCodeStart":822,"sourceCodeEnd":858,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/Connection.java#L822-L858","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)'"],"exampleFix":"// before\nconnection.setClientInfo(appName + \" \" + env); // contains space\n// after\nString info = (appName + \"_\" + env).replaceAll(\"[^!-~]\", \"_\");\nconnection.setClientInfo(info);","handlingStrategy":"validation","validationCode":"static final Pattern SAFE = Pattern.compile(\"[!-~]+\");\nif (!SAFE.matcher(info).matches()) throw new IllegalArgumentException(\"client info must be printable ASCII without spaces\");","typeGuard":"static boolean isSafeClientInfo(String s) { return s != null && s.chars().allMatch(c -> c >= '!' && c <= '~'); }","tryCatchPattern":"try { conn.setClientInfo(info); } catch (JedisValidationException e) { log.warn(\"invalid client info rejected: \" + info); }","preventionTips":["Sanitize labels derived from process/thread/user input","Use '_' instead of spaces in client info","Validate at config time, not at connect time"],"tags":["jedis","validation","client-info"],"backgroundTag":"invalid-argument-format","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}