{"record":{"id":"86dbe98169440249","repo":"grpc/grpc-java","slug":"invalid-character-in-scheme-at-index-i","errorCode":null,"errorMessage":"Invalid character in scheme at index ${i}","messagePattern":"Invalid character in scheme at index (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/grpc/Uri.java","lineNumber":710,"sourceCode":"     * <p>This field is required.\n     *\n     * @return this, for fluent building\n     * @throws IllegalArgumentException if the scheme is invalid.\n     */\n    @CanIgnoreReturnValue\n    public Builder setScheme(String scheme) {\n      return setRawScheme(scheme.toLowerCase(Locale.ROOT));\n    }\n\n    @CanIgnoreReturnValue\n    Builder setRawScheme(String scheme) {\n      if (scheme.isEmpty() || !alphaChars.get(scheme.charAt(0))) {\n        throw new IllegalArgumentException(\"Scheme must start with an alphabetic char\");\n      }\n      for (int i = 0; i < scheme.length(); i++) {\n        char c = scheme.charAt(i);\n        if (!schemeChars.get(c)) {\n          throw new IllegalArgumentException(\"Invalid character in scheme at index \" + i);\n        }\n      }\n      this.scheme = scheme;\n      return this;\n    }\n\n    /**\n     * Specifies the new URI's path component as a string of zero or more '/' delimited segments.\n     *\n     * <p>Path segments can consist of any string of codepoints. Codepoints that can't be encoded\n     * literally will be percent-encoded for you.\n     *\n     * <p>If a URI contains an authority component, then the path component must either be empty or\n     * begin with a slash (\"/\") character. If a URI does not contain an authority component, then\n     * the path cannot begin with two slash characters (\"//\").\n     *\n     * <p>This method interprets all '/' characters in 'path' as segment delimiters. If any of your\n     * segments contain literal '/' characters, call {@link #setRawPath(String)} instead.","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/api/src/main/java/io/grpc/Uri.java#L692-L728","documentation":"Thrown by Uri.Builder's scheme setters when the scheme string contains a character outside the legal scheme alphabet (letters, digits, +, -, .). The first character must be alphabetic (checked separately) and every subsequent character must pass the schemeChars BitSet. This enforces RFC 3986 scheme syntax so the parsed URI is well-formed.","triggerScenarios":"Calling Uri.Builder.setScheme(String) or the create(...) factory with a scheme containing illegal characters such as spaces, underscores, colons, or symbols, e.g. 'my_scheme' or 'h tt p'.","commonSituations":"Building a target URI from user input or environment config where the scheme was hand-assembled instead of using standard 'https'/'dns'; typos like 'grpc://' parsed with the trailing colon included; interpolating values into a scheme string.","solutions":["Remove illegal characters from the scheme; use only [A-Za-z][A-Za-z0-9+.-]*","Lowercase and trim the scheme before passing it in","If parsing a full URI string, strip the 'scheme:' prefix correctly instead of splitting on ':' and including leftovers","Validate the scheme with a regex before calling setScheme"],"exampleFix":"// before\nbuilder.setScheme(schemeAndTarget.split(\":\")[0]); // may contain ':' remnants or '_'\n// after\nString scheme = schemeAndTarget.substring(0, schemeAndTarget.indexOf(':')).trim();\nif (!scheme.matches(\"[A-Za-z][A-Za-z0-9+.-]*\")) { throw new IllegalArgumentException(...); }\nbuilder.setScheme(scheme.toLowerCase(Locale.ROOT));","handlingStrategy":"validation","validationCode":"static boolean isValidScheme(String s) {\n  return s != null && s.matches(\"[A-Za-z][A-Za-z0-9+.\\-]*\");\n}\nif (!isValidScheme(scheme)) throw new IllegalArgumentException(\"bad scheme: \" + scheme);","typeGuard":"boolean isValidScheme(String s) { return s != null && !s.isEmpty() && s.matches(\"[A-Za-z][A-Za-z0-9+.\\-]*\"); }","tryCatchPattern":"try { builder.setScheme(scheme); } catch (IllegalArgumentException e) { log.error(\"Scheme rejected: {}\", scheme, e); throw new ConfigException(\"Invalid URI scheme: \" + scheme); }","preventionTips":["Use only standard schemes like https or dns","Regex-validate schemes built from dynamic input","Trim and lowercase before setting","Never hand-concatenate URI schemes"],"tags":["uri","validation","scheme"],"backgroundTag":"invalid-url-format","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}