{"record":{"id":"82bbd38ece915714","repo":"github/copilot-sdk","slug":"failed-to-apply-default-value-defaultvalue","errorCode":null,"errorMessage":"Failed to apply default value ' + defaultValue + ' for parameter ' + param.name() + ' of type + type.getSimpleName()","messagePattern":"Failed to apply default value ' \\+ defaultValue \\+ ' for parameter ' \\+ param\\.name\\(\\) \\+ ' of type \\+ type\\.getSimpleName\\(\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/rpc/ParamCoercion.java","lineNumber":170,"sourceCode":"            if (type == Short.class || type == short.class) {\n                return (T) Short.valueOf(defaultValue);\n            }\n            if (type == Byte.class || type == byte.class) {\n                return (T) Byte.valueOf(defaultValue);\n            }\n            if (type == Boolean.class || type == boolean.class) {\n                return (T) Boolean.valueOf(defaultValue);\n            }\n            if (type.isEnum()) {\n                Class<? extends Enum> enumType = (Class<? extends Enum>) type;\n                return type.cast(Enum.valueOf(enumType, defaultValue));\n            }\n            // Fallback: let ObjectMapper parse the JSON-encoded default string\n            return mapper.readValue(defaultValue, type);\n        } catch (IllegalArgumentException ex) {\n            throw ex;\n        } catch (Exception ex) {\n            throw new IllegalArgumentException(\"Failed to apply default value '\" + defaultValue + \"' for parameter '\"\n                    + param.name() + \"' of type \" + type.getSimpleName(), ex);\n        }\n    }\n\n    /**\n     * Returns an empty Optional variant for Optional primitive types, or\n     * {@code null} for all other types.\n     *\n     * @param type\n     *            the declared parameter type\n     * @return {@link java.util.OptionalInt#empty()},\n     *         {@link java.util.OptionalLong#empty()},\n     *         {@link java.util.OptionalDouble#empty()}, or {@code null}\n     */\n    static Object emptyOptionalOrNull(Class<?> type) {\n        if (type == java.util.OptionalInt.class) {\n            return java.util.OptionalInt.empty();\n        }","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/rpc/ParamCoercion.java#L152-L188","documentation":"Thrown by ParamCoercion.coerceDefault when a Param's declared string default value cannot be parsed into the parameter's Java type. Simple defaults are parsed directly; otherwise the string is treated as JSON via mapper.readValue. Any failure is wrapped in this IllegalArgumentException, preserving the default value text, parameter name, and target type in the message.","triggerScenarios":"Declaring @Param(defaultValue=\"...\") whose string is not valid JSON for the type — e.g. defaultValue=\"abc\" for an int, unquoted text for String, or malformed JSON for a List/Map.","commonSituations":"Authors forget to JSON-quote string defaults (need \"\\\"abc\\\"\" not \"abc\"); typos in numeric defaults; defaults written for one type then the parameter type changed.","solutions":["Fix the @Param defaultValue string so it parses as JSON for the declared type (quote strings, use bare numerics)","Test the default by coercing it at startup rather than first invocation","Remove the defaultValue and require an explicit argument if no valid default exists","Read ex.getCause() (the Jackson exception) to see exactly why the string failed to parse"],"exampleFix":"// before\nParam<String> name = Param.of(\"name\", String.class, \"unknown-tool\"); // invalid JSON for String\n// after\nParam<String> name = Param.of(\"name\", String.class, \"\\\"unknown-tool\\\"\");","handlingStrategy":"validation","validationCode":"mapper.readValue(defaultValue, declaredType); // call once at startup to validate @Param defaults","typeGuard":"null","tryCatchPattern":"try { tool.invoke(args); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Failed to apply default value\")) { /* fix the Param's defaultValue string */ } else { throw e; } }","preventionTips":["Write defaultValue strings as valid JSON for the declared type (quote strings)","Add a startup test that coerces every Param's default","Never change a Param's type without reviewing its default value"],"tags":["java","rpc","default-value","json"],"backgroundTag":"invalid-argument-format","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}