{"record":{"id":"9e587a928b0b9ec7","repo":"MyCATApache/Mycat-Server","slug":"null-value-for-key","errorCode":null,"errorMessage":"null value for ${key}","messagePattern":"null value for (.+?)","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/utils/MycatPropertyConf.java","lineNumber":29,"sourceCode":"\n    public MycatPropertyConf(){\n\n    }\n\n    /** Set a configuration variable. */\n    public MycatPropertyConf set(String key, String value) {\n        set(key, value, false);\n        return  this;\n    }\n\n\n    public MycatPropertyConf set(String key, String value, boolean silent){\n\n        if (key == null) {\n            throw new NullPointerException(\"null key\");\n        }\n        if (value == null) {\n            throw new NullPointerException(\"null value for \" + key);\n        }\n\n        if (!silent) {\n        }\n\n        settings.put(key, value);\n        return this;\n    }\n\n    public long getSizeAsBytes(String s, long i) {\n        String value = (String) settings.get(s);\n        if(value !=null){\n            return byteStringAsBytes(value);\n        }\n        return i;\n    }\n\n    public long getSizeAsBytes(String s, String defaultValue) {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/utils/MycatPropertyConf.java#L11-L47","documentation":"MycatPropertyConf.set(key, value, silent) rejects a null value with NullPointerException(\"null value for <key>\") naming the offending key. Configuration entries must have non-null string values; use the settings map remove path or a default-getter instead of setting null.","triggerScenarios":"Calling conf.set(\"some.key\", null) or conf.set(\"some.key\", possiblyNull, true) where the value came from a lookup that returned null (e.g. System.getProperty(\"unset.prop\"), map.get, JSON field absent).","commonSituations":"Propagating environment variables or system properties that are unset; deserializing config from JSON/YAML where an optional field is missing; merging default configs where optional entries are null.","solutions":["Substitute a default value when the source is null: set(key, value != null ? value : defaultValue).","Skip the call entirely when value is null instead of setting it.","If the intent is removal, remove the key from settings rather than setting null.","Normalize the config source up front (e.g. Properties.stringPropertyNames loop with null filtering)."],"exampleFix":"// before\nconf.set(\"server.port\", System.getProperty(\"mycat.port\"));\n// after\nString port = System.getProperty(\"mycat.port\", \"8066\");\nconf.set(\"server.port\", port);","handlingStrategy":"validation","validationCode":"if (value == null) { value = DEFAULTS.getOrDefault(key, \"\"); }\nconf.set(key, value);","typeGuard":"static String nonNull(String v, String def) { return v != null ? v : def; }\n// conf.set(key, nonNull(rawValue, defaultValue));","tryCatchPattern":"try { conf.set(key, value); } catch (NullPointerException e) { log.warn(\"skipping null config value for {}\", key); }","preventionTips":["Always supply defaults when reading env/system properties","Filter null entries before bulk-loading configs","Prefer getOrDefault over get for optional settings"],"tags":["null","config","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}