{"record":{"id":"d2527011a45cf333","repo":"apache/pulsar","slug":"field-name-must-not-be-null","errorCode":null,"errorMessage":"Field ${name} must not be null","messagePattern":"Field (.+?) must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ConfigValidationUtils.java","lineNumber":41,"sourceCode":"/**\n * Helper methods for ConfigValidationAnnotations.\n */\npublic class ConfigValidationUtils {\n    /**\n     * Returns a new NestableFieldValidator for a given class.\n     *\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","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ConfigValidationUtils.java#L23-L59","documentation":"ConfigValidationUtils.NestableFieldValidator.validateField throws IllegalArgumentException when a configuration field is null and the validator was built with notNull=true. This is the scalar-type validator: it first rejects nulls, then checks the field is an instance of the expected class.","triggerScenarios":"Validating a config bean (e.g. via ConfigValidation.validateConfig on a Pulsar configuration class) where a field annotated with a notNull field validator is left null because it was absent from the properties/config file and has no default.","commonSituations":"A required setting (e.g. a service URL or cluster name) omitted from broker.conf/standalone.conf or the environment; a field with no default value in the config class not supplied at startup.","solutions":["Set the missing field in the configuration file or properties map passed to validateConfig","Provide an environment variable or default so the field is populated before validation","Add a default value in the config class constructor if the field is legitimately optional, and mark it notNull only when truly required"],"exampleFix":"// before: broker.conf missing required field\n# clusterName=\n// after\nclusterName=my-cluster","handlingStrategy":"validation","validationCode":"// before validateConfig\nfor (String required : new String[]{\"clusterName\", \"serviceUrl\"}) {\n    if (conf.get(required) == null) throw new IllegalStateException(\"missing required config: \" + required);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ConfigValidation.validateConfig(conf);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Invalid configuration: \" + e.getMessage(), e);\n}","preventionTips":["Ship a documented example config listing every required field","Set defaults in the config class for optional fields","Fail fast at startup by validating before connecting","Keep field names in config files spelled exactly as declared"],"tags":["config-validation","null","illegal-argument"],"backgroundTag":"required-config-field-missing","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"}