{"record":{"id":"53e915e7f874fca3","repo":"elastic/elasticsearch","slug":"expected-to-be-type-boolean-but-found-type","errorCode":null,"errorMessage":"expected [{}] to be type [boolean] but found type [{}]","messagePattern":"expected \\[(.+?)\\] to be type \\[boolean\\] but found type \\[(.+?)\\]","errorType":"validation","errorClass":"PolicyValidationException","httpStatus":null,"severity":"error","filePath":"libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlement.java","lineNumber":225,"sourceCode":"            }\n            throw new PolicyValidationException(\n                \"expected [\"\n                    + key\n                    + \"] to be type [\"\n                    + String.class.getSimpleName()\n                    + \"] but found type [\"\n                    + value.getClass().getSimpleName()\n                    + \"]\"\n            );\n        };\n        BiFunction<Map<String, Object>, String, Boolean> checkBoolean = (values, key) -> {\n            Object value = values.remove(key);\n            if (value == null) {\n                return null;\n            } else if (value instanceof Boolean bool) {\n                return bool;\n            }\n            throw new PolicyValidationException(\n                \"expected [\"\n                    + key\n                    + \"] to be type [\"\n                    + boolean.class.getSimpleName()\n                    + \"] but found type [\"\n                    + value.getClass().getSimpleName()\n                    + \"]\"\n            );\n        };\n        List<FileData> filesData = new ArrayList<>();\n        for (Object object : paths) {\n            Map<String, Object> file = new HashMap<>((Map<String, Object>) object);\n            String pathAsString = checkString.apply(file, \"path\");\n            String relativePathAsString = checkString.apply(file, \"relative_path\");\n            String relativeTo = checkString.apply(file, \"relative_to\");\n            String pathSetting = checkString.apply(file, \"path_setting\");\n            String settingBaseDirAsString = checkString.apply(file, \"basedir_if_relative\");\n            String modeAsString = checkString.apply(file, \"mode\");","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlement.java#L207-L243","documentation":"Thrown by the checkBoolean helper in FilesEntitlement.build when the `exclusive` field is present in the entry map but its value is not a JSON boolean. The only fields accepting booleans on a files entry are `exclusive`; supplying a string \"true\" or a number trips this guard.","triggerScenarios":"A files-entitlement entry sets `exclusive` to a non-boolean value, for example `{ \"exclusive\": \"true\" }`, `{ \"exclusive\": 1 }`, or `{ \"exclusive\": \"yes\" }`.","commonSituations":"YAML-derived policy where `exclusive: true` round-tripped into a string; hand-edited JSON with quoted booleans; using 0/1 instead of false/true; locale-specific words (yes/no).","solutions":["Use a real JSON boolean: `true` or `false` without quotes.","If your policy is generated from YAML, ensure the serializer emits booleans, not strings."],"exampleFix":"// before\n{ \"path\": \"/var/log/es\", \"mode\": \"read_write\", \"exclusive\": \"true\" }\n\n// after\n{ \"path\": \"/var/log/es\", \"mode\": \"read_write\", \"exclusive\": true }","handlingStrategy":"type-guard","validationCode":"public static void validateExclusive(Object v) {\n    if (v != null && !(v instanceof Boolean)) {\n        throw new IllegalArgumentException(\"exclusive must be a boolean, got \" + v.getClass().getSimpleName());\n    }\n}","typeGuard":"public static boolean isBooleanOrNullOr(Object v) {\n    return v == null || v instanceof Boolean;\n}","tryCatchPattern":null,"preventionTips":["Use real JSON booleans (true / false) without quotes.","Avoid 0/1 or \"yes\"/\"no\".","Add `type: boolean` to the policy JSON Schema for the exclusive field."],"tags":["entitlements","files","policy","types","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}