{"record":{"id":"f39359f911240872","repo":"karatelabs/karate","slug":"invalid-port-in-callbackports-parts-i","errorCode":null,"errorMessage":"Invalid port in callbackPorts: \" + parts[i]","messagePattern":"Invalid port in callbackPorts: \" \\+ parts\\[i\\]","errorType":"validation","errorClass":"OAuth2Exception","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/AuthorizationCodeAuthHandler.java","lineNumber":299,"sourceCode":"            } 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                }\n            }\n            return ports;\n        }\n        throw new OAuth2Exception(\"Invalid callbackPorts type: \" + portsValue.getClass());\n    }\n\n    private String generateState() {\n        // Simple state generation - could be more sophisticated\n        return java.util.UUID.randomUUID().toString();\n    }\n\n    private String urlEncode(String value) {\n        try {\n            return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());\n        } catch (UnsupportedEncodingException e) {\n            throw new OAuth2Exception(\"URL encoding failed\", e);\n        }","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/AuthorizationCodeAuthHandler.java#L281-L317","documentation":"Thrown by parsePortList when an element of the comma-separated callbackPorts string fails Integer.parseInt. Each comma-separated token must be a valid integer port; the message identifies the exact offending token.","triggerScenarios":"callbackPorts set to a String like \"9090, abc\" or \"9090, ,9091\" — one of the split/trimmed parts is not a valid integer.","commonSituations":"Typo in a port list; accidental double comma leaving an empty segment; trailing comma producing an empty last part; ports pasted with stray characters or units.","solutions":["Correct the callbackPorts string so every comma-separated token is a plain integer, e.g. \"9090,9091,9092\".","Remove empty segments (double/trailing commas) from the list.","Trim whitespace around each port (the code trims, but stray letters/symbols are not tolerated)."],"exampleFix":"// before\n.callbackPorts(\"9090,,9091\") // empty segment\n// after\n.callbackPorts(\"9090,9091\")","handlingStrategy":"validation","validationCode":"Object v = config.get(\"callbackPorts\");\nif (v instanceof String) {\n    for (String part : ((String) v).split(\",\")) {\n        if (!part.trim().matches(\"\\\\d+\")) {\n            throw new IllegalArgumentException(\"Bad port token in callbackPorts: '\" + part + \"'\");\n        }\n    }\n}","typeGuard":"boolean isValidCallbackPorts(Object v) {\n    if (!(v instanceof String)) return false;\n    return java.util.Arrays.stream(((String) v).split(\",\"))\n        .allMatch(s -> s.trim().matches(\"\\\\d+\"));\n}","tryCatchPattern":"try {\n    handler.token();\n} catch (OAuth2Exception e) {\n    if (e.getMessage().startsWith(\"Invalid port in callbackPorts:\")) {\n        logger.error(\"Every comma-separated token must be an integer: {}\", e.getMessage());\n    }\n}","preventionTips":["Keep callbackPorts as 'port,port,port' with no empty segments or trailing commas.","Lint the OAuth config file for this pattern before CI runs.","Prefer explicit small port lists that are all registered with the provider."],"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"}