{"record":{"id":"b0b65d3990226370","repo":"iflytek/astron-agent","slug":"assemble-requesturl-error","errorCode":null,"errorMessage":"assemble requestUrl error:","messagePattern":"assemble requestUrl error:","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AuthStringUtil.java","lineNumber":80,"sourceCode":"        String authParam = String.format(\"hmac-auth api_key=\\\"%s\\\", algorithm=\\\"%s\\\", headers=\\\"%s\\\", signature=\\\"%s\\\"\",\n                apiKey, \"hmac-sha256\", \"host date request-line digest\", sha);\n        String authorization = Base64.getEncoder().encodeToString(authParam.getBytes(charset));\n\n        Map<String, String> header = new HashMap<>();\n        header.put(\"authorization\", authorization);\n        header.put(\"host\", host);\n        header.put(\"date\", date);\n        header.put(\"digest\", digest);\n\n        // Get authentication parameters\n        return uri + \"?\" + header.entrySet()\n                .stream()\n                .map(entry -> {\n                    try {\n                        return URLEncoder.encode(entry.getKey(), String.valueOf(StandardCharsets.UTF_8)) + \"=\" +\n                                URLEncoder.encode(entry.getValue(), String.valueOf(StandardCharsets.UTF_8));\n                    } catch (Exception e) {\n                        throw new RuntimeException(e.getMessage());\n                    }\n                })\n                .collect(Collectors.joining(\"&\"));\n    }\n\n    /**\n     * Generate URL for authentication\n     */\n    public static String assembleRequestUrl(String requestUrl, String method, String apiKey, String apiSecret) {\n        URL url;\n        String httpRequestUrl = requestUrl.replace(\"ws://\", \"http://\").replace(\"wss://\", \"https://\");\n        try {\n            url = new URL(httpRequestUrl);\n            SimpleDateFormat format = new SimpleDateFormat(\"EEE, dd MMM yyyy HH:mm:ss z\", Locale.US);\n            format.setTimeZone(TimeZone.getTimeZone(\"UTC\"));\n            String date = format.format(new Date());\n            String host = url.getHost();\n            String builder = \"host: \" + host + \"\\n\" +","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AuthStringUtil.java#L62-L98","documentation":"assembleAuthURL builds a percent-encoded query string from request parameters using URLEncoder. If encoding any key/value throws (e.g. an unsupported charset name at runtime), the lambda wraps it in a RuntimeException with the message 'assemble requestUrl error:'. It is a defensive catch-all; under normal UTF-8 setup it should never fire.","triggerScenarios":"Calling AuthStringUtil.assembleAuthURL with a parameter map whose key or value fails URLEncoder.encode — practically only when String.valueOf(StandardCharsets.UTF_8) cannot resolve to a supported charset in a stripped/restricted JVM environment.","commonSituations":"Running on a minimal JRE without the UTF-8 charset provider; exotic custom security policies blocking charset lookup; repackaging the utility into an environment with a broken java.nio.charset setup.","solutions":["Verify the JVM supports the UTF-8 charset (standard JVMs do; a custom/minimal JRE may not)","Prefer the overload URLEncoder.encode(value, StandardCharsets.UTF_8) (Java 10+) so no charset-name lookup happens","Improve the wrapper to preserve the cause: new RuntimeException(e) instead of only e.getMessage()","Log the offending key/value type to pinpoint which entry failed encoding"],"exampleFix":"// before\nURLEncoder.encode(entry.getKey(), String.valueOf(StandardCharsets.UTF_8))\n// after\nURLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)","handlingStrategy":"try-catch","validationCode":"if (params == null || params.isEmpty()) throw new IllegalArgumentException(\"auth params required\");","typeGuard":null,"tryCatchPattern":"try { String url = AuthStringUtil.assembleAuthURL(baseUrl, params); } catch (RuntimeException e) { log.error(\"auth URL assembly failed: {}\", e.getMessage(), e); throw new ServiceException(\"Unable to build auth URL\"); }","preventionTips":["Use the Charset-object URLEncoder overload (Java 10+) to avoid charset-name lookup failures","Run on a standard JVM that guarantees UTF-8 support","Log the full cause, not just getMessage(), when wrapping exceptions"],"tags":["java","url-encoding","runtime-exception"],"backgroundTag":"invalid-url-format","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}