{"record":{"id":"143d7b84e7055c31","repo":"prestodb/presto","slug":"invalid-token-uri","errorCode":null,"errorMessage":"Invalid token URI: ","messagePattern":"Invalid token URI: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-client/src/main/java/com/facebook/presto/client/auth/external/HttpTokenPoller.java","lineNumber":124,"sourceCode":"                        try (Response response = client.get().newCall(request)\n                                .execute()) {\n                            return response.code();\n                        }\n                    });\n        }\n        catch (FailsafeException e) {\n            if (e.getCause() instanceof IOException) {\n                throw new UncheckedIOException((IOException) e.getCause());\n            }\n            throw e;\n        }\n    }\n\n    private static Request.Builder prepareRequestBuilder(URI tokenUri)\n    {\n        HttpUrl url = HttpUrl.get(tokenUri);\n        if (url == null) {\n            throw new IllegalArgumentException(\"Invalid token URI: \" + tokenUri);\n        }\n\n        return new Request.Builder()\n                .url(url)\n                .addHeader(USER_AGENT, USER_AGENT_VALUE);\n    }\n\n    private TokenPollResult executePoll(Request request)\n            throws IOException\n    {\n        JsonResponse<TokenPollRepresentation> response = executeRequest(request);\n\n        if ((response.getStatusCode() == HTTP_OK) && response.hasValue()) {\n            return response.getValue().toResult();\n        }\n\n        Optional<String> responseBody = Optional.ofNullable(response.getResponseBody());\n        String message = format(\"Request to %s failed: %s [Error: %s]\", request.url(), response, responseBody.orElse(\"<Response Too Large>\"));","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-client/src/main/java/com/facebook/presto/client/auth/external/HttpTokenPoller.java#L106-L142","documentation":"HttpTokenPoller.prepareRequestBuilder converts the tokenUri from the authentication challenge into an OkHttp HttpUrl via HttpUrl.get(tokenUri), which returns null when the URI cannot be represented as a valid HTTP(S) URL (e.g. missing scheme or non-http scheme). It then throws this IllegalArgumentException naming the offending URI.","triggerScenarios":"pollForToken/request path receives a tokenUri from the external-auth challenge whose scheme is not http/https (e.g. a relative or 'localhost:...' schemeless URI) so HttpUrl.get returns null, triggering the exception before any request is built.","commonSituations":"Authentication service emitting a token URI without the http(s):// scheme; trailing whitespace or invalid characters in the configured URI; mixing ws:// or custom schemes that OkHttp's HttpUrl rejects for a token poll.","solutions":["Correct the tokenUri emitted by the authentication service to be an absolute http:// or https:// URL.","Verify the URI parses as an HTTP URL before invoking the authenticator (HttpUrl.get(...) != null or starts with http).","Check for hidden whitespace/encoding issues in the challenge field or config and trim/normalize the URI.","If you control the client, validate with HttpUrl.parse and fail early with a clearer message."],"exampleFix":"// before\ntokenUri = \"auth.example.com/token\";          // no scheme -> HttpUrl.get returns null\n// after\ntokenUri = \"https://auth.example.com/token\";  // valid HTTP URL","handlingStrategy":"validation","validationCode":"okhttp3.HttpUrl parsed = okhttp3.HttpUrl.parse(tokenUri);\nif (parsed == null || !(parsed.isHttps() || parsed.isHttp())) {\n    throw new IllegalArgumentException(\"tokenUri must be an absolute http(s) URL: \" + tokenUri);\n}","typeGuard":"boolean isValidHttpUrl(URI tokenUri) {\n    String s = tokenUri.toString().trim();\n    return okhttp3.HttpUrl.parse(s) != null;\n}","tryCatchPattern":"try {\n    poller.pollForToken(httpClient, fields, timeout);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Authentication service returned invalid tokenUri: \" + e.getMessage(), e);\n}","preventionTips":["Ensure tokenUri always includes http:// or https:// scheme.","Normalize/trim URIs from challenge fields before polling.","Validate with HttpUrl.parse in your own config-loading code before starting auth.","Pin the auth service to emit standard https URLs; reject custom schemes early."],"tags":["authentication","uri","okhttp","validation"],"backgroundTag":"invalid-uri-format","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}