{"record":{"id":"5b6fd5581e12d177","repo":"karatelabs/karate","slug":"invalid-callbackport-portvalue","errorCode":null,"errorMessage":"Invalid callbackPort: \" + portValue","messagePattern":"Invalid callbackPort: \" \\+ portValue","errorType":"validation","errorClass":"OAuth2Exception","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/AuthorizationCodeAuthHandler.java","lineNumber":282,"sourceCode":"            return parsePortList(callbackPorts);\n        }\n\n        // Default ports (Postman-style)\n        return new int[] { 8080, 8888, 9090, 3000 };\n    }\n\n    /**\n     * Parse a single port value\n     */\n    private int parsePort(Object portValue) {\n        if (portValue instanceof Integer) {\n            return (Integer) portValue;\n        }\n        if (portValue instanceof String) {\n            try {\n                return Integer.parseInt((String) portValue);\n            } catch (NumberFormatException e) {\n                throw new OAuth2Exception(\"Invalid callbackPort: \" + portValue);\n            }\n        }\n        throw new OAuth2Exception(\"Invalid callbackPort type: \" + portValue.getClass());\n    }\n\n    /**\n     * Parse comma-separated port list\n     */\n    private int[] parsePortList(Object portsValue) {\n        if (portsValue instanceof String) {\n            String[] parts = ((String) portsValue).split(\",\");\n            int[] ports = new int[parts.length];\n            for (int i = 0; i < parts.length; i++) {\n                try {\n                    ports[i] = Integer.parseInt(parts[i].trim());\n                } catch (NumberFormatException e) {\n                    throw new OAuth2Exception(\"Invalid port in callbackPorts: \" + parts[i]);\n                }","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/AuthorizationCodeAuthHandler.java#L264-L300","documentation":"Thrown by parsePort when the callbackPort config value is a String that cannot be parsed as an integer. The library accepts callbackPort as an Integer or a numeric String; anything else (e.g. \"abc\", \"8080x\", empty string, or a value with stray whitespace/symbols) is rejected.","triggerScenarios":"callbackPort in the auth/config map is set to a String like \"abc\", \"\", \"port 8080\", or a number with trailing characters, so Integer.parseInt fails with NumberFormatException.","commonSituations":"Typo or stray character in a Karate config file; value read from an environment variable or properties file that contains whitespace or a comment; copy-paste including quotes or units ('8080px').","solutions":["Set callbackPort to a plain integer either as a number (8080) or a clean numeric string (\"8080\").","Trim whitespace and remove any non-digit characters from the configured value.","If the value comes from an env var, validate/parse it before passing it into the OAuth2 config."],"exampleFix":"// before\nconfig.callbackPort = \" 8080 \"; // unparseable with spaces in some paths / or \"abc\"\n// after\nconfig.callbackPort = 8080; // Integer, or \"8080\" trimmed","handlingStrategy":"validation","validationCode":"Object v = config.get(\"callbackPort\");\nif (v instanceof String) {\n    if (!((String) v).trim().matches(\"\\\\d+\")) {\n        throw new IllegalArgumentException(\"callbackPort must be numeric, got: \" + v);\n    }\n}","typeGuard":"boolean isValidCallbackPort(Object v) {\n    if (v instanceof Integer) return true;\n    return v instanceof String && ((String) v).trim().matches(\"\\\\d+\");\n}","tryCatchPattern":"try {\n    handler.token();\n} catch (OAuth2Exception e) {\n    if (e.getMessage().startsWith(\"Invalid callbackPort:\")) {\n        logger.error(\"Fix callbackPort to a plain integer: {}\", e.getMessage());\n    }\n}","preventionTips":["Store callbackPort as a JSON/YAML number, not a decorated string.","Trim and sanitize values sourced from env vars or properties files.","Validate the whole OAuth2 config map before starting the flow."],"tags":["oauth2","configuration","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}