{"record":{"id":"5f13e05526121f43","repo":"jwtk/jjwt","slug":"unable-to-convert-string-value-s-to-uri-insta","errorCode":null,"errorMessage":"Unable to convert String value '${s}' to URI instance: ${e.getMessage()}","messagePattern":"Unable to convert String value '(.+?)' to URI instance: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/lang/UriStringConverter.java","lineNumber":37,"sourceCode":"\nimport java.net.URI;\n\npublic class UriStringConverter implements Converter<URI, CharSequence> {\n\n    @Override\n    public String applyTo(URI uri) {\n        Assert.notNull(uri, \"URI cannot be null.\");\n        return uri.toString();\n    }\n\n    @Override\n    public URI applyFrom(CharSequence s) {\n        Assert.hasText(s, \"URI string cannot be null or empty.\");\n        try {\n            return URI.create(s.toString());\n        } catch (Exception e) {\n            String msg = \"Unable to convert String value '\" + s + \"' to URI instance: \" + e.getMessage();\n            throw new IllegalArgumentException(msg, e);\n        }\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":41,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/lang/UriStringConverter.java#L19-L41","documentation":"UriStringConverter.applyFrom converts a CharSequence to a java.net.URI via URI.create, first asserting it has text. If URI.create throws (IllegalArgumentException due to invalid URI syntax, etc.), the converter wraps it in an IllegalArgumentException including the original string and the cause message.","triggerScenarios":"Setting a URI-typed claim (e.g. 'jwk' URLs, 'iss' values converted via this converter, OIDC discovery URLs) with a syntactically invalid string containing spaces, illegal characters, or unmatched brackets.","commonSituations":"Unencoded spaces or non-ASCII characters in URLs; building URLs by string concatenation with missing scheme ('example.com/x' instead of 'https://example.com/x'); config values with trailing whitespace or quotes.","solutions":["Ensure the string is a syntactically valid absolute URI: scheme://host/path with illegal characters percent-encoded.","Encode query/path parameters with URLEncoder/UriComponentsBuilder before composing the URL.","Validate with URI.create(...) yourself in a try/catch to surface a clearer message before calling the API."],"exampleFix":"// before\njwtBuilder.claim(\"jku\", \"https://example.com/my keys/jwks.json\");\n// after\njwtBuilder.claim(\"jku\", \"https://example.com/my%20keys/jwks.json\");","handlingStrategy":"validation","validationCode":"URI safeUri(String s) {\n    if (s == null || s.isBlank()) throw new IllegalArgumentException(\"URI string cannot be null or empty.\");\n    try {\n        return URI.create(s);\n    } catch (IllegalArgumentException e) {\n        throw new IllegalArgumentException(\"Invalid URI: '\" + s + \"'\", e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    converter.applyFrom(raw);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to convert String value\")) {\n        // inspect the raw string for spaces/illegal chars/missing scheme\n    }\n    throw e;\n}","preventionTips":["Percent-encode spaces and special characters in URLs before setting URI claims","Always include an explicit scheme (https://)","Validate configuration-provided URLs at startup with URI.create"],"tags":["uri","url-parsing","illegal-argument"],"backgroundTag":"invalid-url-format","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}