{"record":{"id":"4427e3d334dd0cdc","repo":"apache/pulsar","slug":"pd-name-must-be-a-cls-getname-field","errorCode":null,"errorMessage":"${pd}${name} must be a ${cls.getName()}. (${field})","messagePattern":"(.+?)(.+?) must be a (.+?)\\. \\((.+?)\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ConfigValidationUtils.java","lineNumber":47,"sourceCode":"     *\n     * @param cls     the Class the field should be a type of\n     * @param notNull whether or not a value of null is valid\n     * @return a NestableFieldValidator for that class\n     */\n    public static NestableFieldValidator fv(final Class<?> cls, final boolean notNull) {\n        return new NestableFieldValidator() {\n            @Override\n            public void validateField(String pd, String name, Object field)\n                    throws IllegalArgumentException {\n                if (field == null) {\n                    if (notNull) {\n                        throw new IllegalArgumentException(\"Field \" + name + \" must not be null\");\n                    } else {\n                        return;\n                    }\n                }\n                if (!cls.isInstance(field)) {\n                    throw new IllegalArgumentException(\n                            pd + name + \" must be a \" + cls.getName() + \". (\" + field + \")\");\n                }\n            }\n        };\n    }\n\n    /**\n     * Returns a new NestableFieldValidator for a List of the given Class.\n     *\n     * @param cls     the Class of elements composing the list\n     * @param notNull whether or not a value of null is valid\n     * @return a NestableFieldValidator for a list of the given class\n     */\n    public static NestableFieldValidator listFv(Class<?> cls, boolean notNull) {\n        return listFv(fv(cls, notNull), notNull);\n    }\n\n    /**","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ConfigValidationUtils.java#L29-L65","documentation":"The scalar NestableFieldValidator throws IllegalArgumentException when the field is non-null but is not an instance of the expected class (cls.isInstance(field) fails). The message includes the field descriptor prefix, name, expected class, and the offending value.","triggerScenarios":"A config property is parsed/set with the wrong Java type — e.g. a String where an Integer/long is expected, a String 'true' where a boolean is expected — then passed through validateField during ConfigValidation.validateConfig.","commonSituations":"Typo'd values in broker.conf (a port given as 'http://...' instead of a number); a JSON/YAML config where numbers were quoted as strings; programmatic construction of a config object with wrong types.","solutions":["Correct the value's type in the config file (remove quotes around numbers/booleans in JSON/YAML)","If set programmatically, assign the declared field type (Integer, Long, boolean, etc.) exactly","Check the config class field declaration to see the expected class named in the message"],"exampleFix":"// before (YAML)\nport: \"6650\"\n// after\nport: 6650","handlingStrategy":"validation","validationCode":"// before validateConfig: coerce common string->number cases\nObject port = conf.get(\"port\");\nif (port instanceof String) conf.put(\"port\", Integer.valueOf((String) port));","typeGuard":"static <T> boolean isInstance(T expected, Object o) { return expected != null && expected.getClass().isInstance(o); }","tryCatchPattern":"try {\n    ConfigValidation.validateConfig(conf);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Config type error (check quoting/units): \" + e.getMessage(), e);\n}","preventionTips":["Do not quote numbers/booleans in JSON/YAML configs","Match the Java field type declared in the config class","Validate once at startup, printing the offending field name from the message"],"tags":["config-validation","type-mismatch","illegal-argument"],"backgroundTag":"config-type-mismatch","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}