{"record":{"id":"c898416ccece4a9f","repo":"apache/pulsar","slug":"invalid-url-format","errorCode":null,"errorMessage":"Invalid URL format","messagePattern":"Invalid URL format","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-auth-athenz/src/main/java/org/apache/pulsar/client/impl/auth/AuthenticationAthenz.java","lineNumber":310,"sourceCode":"            ZTSClient.setPrefetchAutoEnable(this.autoPrefetchEnabled);\n        }\n        return ztsClient;\n    }\n\n    private static void checkRequiredParams(Map<String, String> authParams, String... requiredParams) {\n        for (String param : requiredParams) {\n            checkArgument(isNotBlank(authParams.get(param)), \"Missing required parameter: %s\", param);\n        }\n    }\n\n    private static String getAbsolutePathFromUrl(String urlString) {\n        try {\n            java.net.URL url = new URL(urlString).openConnection().getURL();\n            checkArgument(\"file\".equals(url.getProtocol()), \"Unsupported protocol: %s\", url.getProtocol());\n            Path path = Paths.get(url.getPath());\n            return path.isAbsolute() ? path.toString() : path.toAbsolutePath().toString();\n        } catch (URISyntaxException e) {\n            throw new IllegalArgumentException(\"Invalid URL format\", e);\n        } catch (InstantiationException | IllegalAccessException | IOException e) {\n            throw new IllegalArgumentException(\"Cannnot get absolute path from specified URL\", e);\n        }\n    }\n\n    private static PrivateKey loadPrivateKey(String privateKeyURL) {\n        PrivateKey privateKey = null;\n        try {\n            URLConnection urlConnection = new URL(privateKeyURL).openConnection();\n            String protocol = urlConnection.getURL().getProtocol();\n            if (\"data\".equals(protocol) && !APPLICATION_X_PEM_FILE.equals(urlConnection.getContentType())) {\n                throw new IllegalArgumentException(\n                        \"Unsupported media type or encoding format: \" + urlConnection.getContentType());\n            }\n            String keyData = CharStreams.toString(new InputStreamReader((InputStream) urlConnection.getContent(),\n                    Charset.defaultCharset()));\n            privateKey = Crypto.loadPrivateKey(keyData);\n        } catch (URISyntaxException e) {","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-auth-athenz/src/main/java/org/apache/pulsar/client/impl/auth/AuthenticationAthenz.java#L292-L328","documentation":"getAbsolutePathFromUrl converts a file URL to an absolute filesystem path. If the URL string cannot be parsed (URISyntaxException thrown when normalizing the URL via new URL(urlString).openConnection().getURL()), it is wrapped as IllegalArgumentException('Invalid URL format').","triggerScenarios":"Calling setAuthParams/configure with a privateKeyPath value that is not a syntactically valid URL — e.g. spaces in the path, malformed 'file:/...' syntax, or control characters — so URL construction throws URISyntaxException.","commonSituations":"Paths with unencoded spaces or non-ASCII characters; Windows paths pasted as 'C:\\keys\\x.pem' without the file:/// scheme; partially edited config leaving a truncated URL.","solutions":["Percent-encode the path and use a proper file URL: 'file:///etc/pulsar/my%20key.pem' (or escape spaces)","Verify the URL parses: new URI(value) in a quick check before configuring","Prefer a simple absolute path without special characters, or base64-embed the key via the data: URI in 'privateKey'"],"exampleFix":"// before\n{\"privateKeyPath\":\"file:///etc/pulsar/my key.pem\"}\n// after\n{\"privateKeyPath\":\"file:///etc/pulsar/my%20key.pem\"}","handlingStrategy":"validation","validationCode":"try {\n    new URI(pathOrUrl).toURL();\n} catch (URISyntaxException | MalformedURLException e) {\n    throw new IllegalArgumentException(\"privateKeyPath must be a valid URL, got: \" + pathOrUrl, e);\n}","typeGuard":"boolean isValidUrl(String s) {\n    try { new URI(s).toURL(); return true; } catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n    authentication.configure(authParamsJson);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Invalid URL format\")) {\n        log.error(\"privateKeyPath is not a parseable URL; percent-encode spaces and use file:///\");\n    }\n    throw e;\n}","preventionTips":["Percent-encode spaces and special characters in file URLs","Always use the file:/// scheme with an absolute path","Test the URL with new URI(...).toURL() in unit tests for your config loader"],"tags":["java","url","athenz","auth-config"],"backgroundTag":"invalid-url-format","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}