{"record":{"id":"5f131fe792aa1e3c","repo":"github/copilot-sdk","slug":"defaultvalue-defaultvalue-is-not-valid-for-typ","errorCode":null,"errorMessage":"defaultValue '<defaultValue>' is not valid for type <type simple name>","messagePattern":"defaultValue '<defaultValue>' is not valid for type <type simple name>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/tool/Param.java","lineNumber":288,"sourceCode":"                return;\n            }\n            if (type == Byte.class || type == byte.class) {\n                Byte.parseByte(defaultValue);\n                return;\n            }\n            if (type == Boolean.class || type == boolean.class) {\n                if (!\"true\".equalsIgnoreCase(defaultValue) && !\"false\".equalsIgnoreCase(defaultValue)) {\n                    throw new IllegalArgumentException(\"must be 'true' or 'false'\");\n                }\n                return;\n            }\n            if (type.isEnum()) {\n                Class<? extends Enum> enumType = (Class<? extends Enum>) type;\n                Enum.valueOf(enumType, defaultValue);\n                return;\n            }\n        } catch (RuntimeException ex) {\n            throw new IllegalArgumentException(\n                    \"defaultValue '\" + defaultValue + \"' is not valid for type \" + type.getSimpleName(), ex);\n        }\n\n        throw new IllegalArgumentException(\n                \"defaultValue is not supported for type \" + type.getName() + \" without a custom coercion policy\");\n    }\n}\n","sourceCodeStart":270,"sourceCodeEnd":296,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/tool/Param.java#L270-L296","documentation":"Param.validateDefaultValue() throws this when a default value string cannot be coerced/validated against the parameter's declared type. For enums it uses Enum.valueOf, so a name that is not an exact enum constant (wrong case, whitespace, or a value rather than a name) throws IllegalArgumentException with this message. The original RuntimeException is attached as the cause.","triggerScenarios":"Constructing a Param with a defaultValue where: the type is an enum and the string does not exactly match an enum constant name; or a RuntimeException occurs during built-in coercion of the default value for the type.","commonSituations":"Passing the enum's underlying value or label instead of its constant name; case mismatch (e.g. 'read' vs 'READ'); trailing whitespace from config files; locale/copy-paste typos in defaults declared in tool definitions.","solutions":["Change defaultValue to exactly match the enum constant name (case-sensitive, no whitespace)","Print the allowed values with ClassName.values() / ClassName.<value>?.name and pick one","If the desired default is not a constant name, wrap the type with a custom coercion policy instead of relying on built-in validation"],"exampleFix":"// before\nnew Param(\"mode\", Mode.class, \"read\");\n// after\nnew Param(\"mode\", Mode.class, \"READ\");","handlingStrategy":"validation","validationCode":"boolean ok = java.util.Arrays.stream(Mode.values()).anyMatch(e -> e.name().equals(defaultValue));\nif (!ok) throw new IllegalArgumentException(\"default must be one of: \" + java.util.Arrays.toString(Mode.values()));","typeGuard":"boolean isValidEnumName(Class<? extends Enum<?>> t, String v) { return v != null && java.util.Arrays.stream(t.getEnumConstants()).anyMatch(e -> e.name().equals(v)); }","tryCatchPattern":"try { new Param(\"mode\", Mode.class, candidate); } catch (IllegalArgumentException ex) { log.error(\"Bad default: {}\", candidate, ex); }","preventionTips":["Always use enum constant names, not values or labels","Trim and case-check default strings sourced from config","Add a unit test constructing each Param with its declared default"],"tags":["java","validation","enum"],"backgroundTag":"invalid-enum-value","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"}