{"record":{"id":"09da1714db7666c6","repo":"apache/pulsar","slug":"field-name-must-be-of-type-type-object-o","errorCode":null,"errorMessage":"Field ${name} must be of type ${type}. Object: ${o} actual type: ${o.getClass()}","messagePattern":"Field (.+?) must be of type (.+?)\\. Object: (.+?) actual type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ValidatorImpls.java","lineNumber":370,"sourceCode":"    /**\n     * Validates basic types.\n     */\n    public static class SimpleTypeValidator extends Validator {\n\n        private Class<?> type;\n\n        public SimpleTypeValidator(Map<String, Object> params) {\n            this.type = (Class<?>) params.get(ConfigValidationAnnotations.ValidatorParams.TYPE);\n        }\n\n        public static void validateField(String name, Class<?> type, Object o) {\n            if (o == null) {\n                return;\n            }\n            if (type.isInstance(o)) {\n                return;\n            }\n            throw new IllegalArgumentException(\n                    \"Field \" + name + \" must be of type \" + type + \". Object: \" + o + \" actual type: \" + o.getClass());\n        }\n\n        @Override\n        public void validateField(String name, Object o) {\n            validateField(name, this.type, o);\n        }\n    }\n\n    private static Class<?> loadClass(String className) throws ClassNotFoundException {\n        Class<?> objectClass;\n        try {\n            objectClass = Class.forName(className);\n        } catch (ClassNotFoundException e) {\n            ClassLoader clsLoader = Thread.currentThread().getContextClassLoader();\n            if (clsLoader != null) {\n                objectClass = clsLoader.loadClass(className);\n            } else {","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ValidatorImpls.java#L352-L388","documentation":"Thrown by a simple type validator when a non-null field value is not an instance of the expected type. Null values are allowed (early return), and exact instances return early; anything else fails with the expected type, the object, and its actual runtime class.","triggerScenarios":"A config map (typically Map<String,Object> parsed from YAML/properties) supplies a value of the wrong Java type for a field — e.g. an Integer where a String is required, or a List where a Map is expected — and validateField(name, type, o) is called on it.","commonSituations":"YAML/JSON auto-typing turning \"on\"/numbers into booleans/integers; user writes a bare number where a string is expected; nested list/map structure mismatch; age setting given as string vs int after a schema change.","solutions":["Change the config value so its type matches the declared field type shown in the message.","Quote values that must stay strings in YAML (e.g. name: \"12345\") to defeat implicit typing.","Fix nested structures (map vs list) to match the schema of the config class.","Convert values programmatically (String.valueOf / Number parsing) before passing them to validation."],"exampleFix":"// before (YAML) — parsed as Integer\nmaxRedeliverCount: \"3\"\n// after — ensure declared type matches, or explicitly convert in code\nint v = Integer.parseInt(o.toString());\nvalidator.validateField(\"maxRedeliverCount\", v);","handlingStrategy":"type-guard","validationCode":"static <T> boolean isExpectedType(Object o, Class<T> type) {\n    return o == null || type.isInstance(o);\n}","typeGuard":"static <T> T coerce(Object o, Class<T> type) {\n    if (o == null) return null;\n    if (type.isInstance(o)) return type.cast(o);\n    if (type == String.class) return type.cast(String.valueOf(o));\n    throw new IllegalArgumentException(\"Expected \" + type + \" got \" + o.getClass());\n}","tryCatchPattern":"try {\n    validator.validateField(\"maxRedeliverCount\", value);\n} catch (IllegalArgumentException e) {\n    log.error(\"Config type mismatch: {}\", e.getMessage());\n    throw new ConfigurationException(e.getMessage(), e);\n}","preventionTips":["Quote values in YAML that must remain strings (version: \"1.0\", id: \"0123\").","Be aware YAML/JSON auto-type booleans and numbers (yes/no/on/off, leading zeros).","Use typed config beans with strict parsers instead of raw Map<String,Object>.","Run schema validation on config files in CI before deployment."],"tags":["java","type-mismatch","config-validation","yaml"],"backgroundTag":"type-mismatch","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}