{"record":{"id":"e0cfc16f587fb871","repo":"github/copilot-sdk","slug":"must-be-true-or-false","errorCode":null,"errorMessage":"must be 'true' or 'false'","messagePattern":"must be 'true' or 'false'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/tool/Param.java","lineNumber":278,"sourceCode":"            if (type == Double.class || type == double.class) {\n                Double.parseDouble(defaultValue);\n                return;\n            }\n            if (type == Float.class || type == float.class) {\n                Float.parseFloat(defaultValue);\n                return;\n            }\n            if (type == Short.class || type == short.class) {\n                Short.parseShort(defaultValue);\n                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":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/tool/Param.java#L260-L296","documentation":"When a Param's declared type is Boolean/boolean, validateDefaultValue checks that the defaultValue string is exactly 'true' or 'false' (case-insensitive); otherwise it throws this IllegalArgumentException. Note the message omits field context, but it is raised only for boolean-typed parameters during construction.","triggerScenarios":"new Param(..., type=Boolean.class, defaultValue=\"yes\"/\"1\"/\"on\"/\"true \") — any string other than true/false (ignoring case).","commonSituations":"Config files using truthy conventions like yes/no or 1/0, YAML-style booleans pasted into a JSON/Java context, trailing whitespace from untrimmed config values.","solutions":["Change the defaultValue to \"true\" or \"false\".","Normalize the incoming config value before constructing the Param (map yes/on/1 to true).","Use Boolean.parseBoolean's accepted set as your validation upstream so only true/false reach Param."],"exampleFix":"// before\nnew Param(\"verbose\", \"desc\", Type.BOOLEAN, \"yes\", false, null);\n// after\nnew Param(\"verbose\", \"desc\", Type.BOOLEAN, \"true\", false, null);","handlingStrategy":"validation","validationCode":"static String normalizeBooleanDefault(String v) {\n    if (v == null) return null;\n    String t = v.trim().toLowerCase();\n    switch (t) {\n        case \"true\": case \"yes\": case \"on\": case \"1\": return \"true\";\n        case \"false\": case \"no\": case \"off\": case \"0\": return \"false\";\n        default: throw new IllegalArgumentException(\"boolean default must be true/false: \" + v);\n    }\n}","typeGuard":"static boolean isBooleanLiteral(String s) {\n    return \"true\".equalsIgnoreCase(s) || \"false\".equalsIgnoreCase(s);\n}","tryCatchPattern":"try {\n    new Param(name, desc, Boolean.class, def, false, null);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"must be 'true' or 'false'\")) {\n        // def was not a boolean literal — normalize and retry\n    }\n    throw e;\n}","preventionTips":["Store boolean defaults as literal true/false strings only.","Normalize config values (yes/no/1/0) before passing them as defaults.","Trim strings from config files to avoid 'true ' with trailing whitespace."],"tags":["validation","boolean","tool-parameters","type-mismatch"],"backgroundTag":"invalid-argument-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"}