{"record":{"id":"81e442d9112a829f","repo":"karatelabs/karate","slug":"invalid-callbackports-type-portsvalue-getclass","errorCode":null,"errorMessage":"Invalid callbackPorts type: \" + portsValue.getClass()","messagePattern":"Invalid callbackPorts type: \" \\+ portsValue\\.getClass\\(\\)","errorType":"validation","errorClass":"OAuth2Exception","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/AuthorizationCodeAuthHandler.java","lineNumber":304,"sourceCode":"    }\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        }\n    }\n\n    private String truncate(String value) {\n        if (value == null) {\n            return \"(empty)\";","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/AuthorizationCodeAuthHandler.java#L286-L322","documentation":"Type guard in parsePortList: callbackPorts in the OAuth2 authorization-code config must be a string or list of ports, but a value of an unexpected type (portsValue.getClass() is interpolated into the message) was supplied. Fix the config so callbackPorts is a comma-separated string or a compatible list.","triggerScenarios":"callbackPorts configured as a List, Map, Long array, or other object instead of a comma-separated String or int[].","commonSituations":"Passing a JS array or JSON array directly where the handler expects the documented string form (or int[]); a YAML list binding to java.util.List; programmatic config with the wrong collection type.","solutions":["Provide callbackPorts as a comma-separated String (\"9090,9091\") or an int[] (new int[]{9090, 9091}).","If you have a List<Long>/JS array, convert it: convert each element to int and build an int[].","Check the docs/config schema for the accepted callbackPorts types and fix the assignment."],"exampleFix":"// before\nconfig.callbackPorts = [9090, 9091]; // JS/JSON list\n// after\nconfig.callbackPorts = \"9090,9091\"; // or new int[]{9090, 9091}","handlingStrategy":"type-guard","validationCode":"Object v = config.get(\"callbackPorts\");\nif (!(v instanceof String) && !(v instanceof int[])) {\n    throw new IllegalArgumentException(\"callbackPorts must be a String or int[], got: \" + v.getClass());\n}","typeGuard":"boolean isAcceptedCallbackPortsType(Object v) {\n    return v instanceof String || v instanceof int[];\n}\n// convert a JS/JSON numeric array:\nString portsToString(java.util.List<Number> list) {\n    StringBuilder sb = new StringBuilder();\n    for (Number n : list) { if (sb.length() > 0) sb.append(','); sb.append(n.intValue()); }\n    return sb.toString();\n}","tryCatchPattern":"try {\n    handler.token();\n} catch (OAuth2Exception e) {\n    if (e.getMessage().startsWith(\"Invalid callbackPorts type:\")) {\n        logger.error(\"Use a comma-separated String or int[] for callbackPorts: {}\", e.getMessage());\n    }\n}","preventionTips":["Do not pass JSON/JS arrays or YAML lists directly to callbackPorts.","Convert collections to a comma-separated string or int[] at config-build time.","Document the accepted types in your team's config template."],"tags":["oauth2","configuration","type-mismatch"],"backgroundTag":"type-mismatch","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"}