{"record":{"id":"63b76dfb453c1586","repo":"MyCATApache/Mycat-Server","slug":"null-key","errorCode":null,"errorMessage":"null key","messagePattern":"null key","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/utils/MycatPropertyConf.java","lineNumber":26,"sourceCode":"public class MycatPropertyConf {\n\n    private ConcurrentHashMap settings = new ConcurrentHashMap<String, String>();\n\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;","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/utils/MycatPropertyConf.java#L8-L44","documentation":"MycatPropertyConf.set(key, value, silent) explicitly rejects a null configuration key with NullPointerException(\"null key\"). The settings map cannot meaningfully hold a null key, so the library fails fast at the public setter.","triggerScenarios":"Calling conf.set(null, \"someValue\") directly, or via the two-arg set(key, value) overload when a variable holding the key is null — typically a config name read from a map/properties file that was absent.","commonSituations":"Building config programmatically from lookup tables where a key constant was misspelled or a Map.get() returned null; refactoring where the key argument was accidentally reordered with value.","solutions":["Ensure the key is a non-null String before calling set; check the source of the key variable.","Fix Map.get()/getProperty() call sites to handle missing keys instead of passing null through.","Swap arguments if key and value were accidentally reversed (though here the key itself is null).","Wrap config assembly in a helper that asserts non-null keys and throws a descriptive IllegalArgumentException."],"exampleFix":"// before\nString key = props.get(\"thread.count\"); // may be null\nconf.set(key, \"8\");\n// after\nString key = props.get(\"thread.count\");\nif (key != null) conf.set(key, \"8\");","handlingStrategy":"type-guard","validationCode":"if (key == null) throw new IllegalArgumentException(\"config key must not be null\");\nconf.set(key, value);","typeGuard":"static String requireKey(String k) { if (k == null) throw new IllegalArgumentException(\"null config key\"); return k; }\n// conf.set(requireKey(k), v);","tryCatchPattern":"try { conf.set(key, value); } catch (NullPointerException e) { if (\"null key\".equals(e.getMessage())) throw new IllegalArgumentException(\"Config key was null; check key source\"); throw e; }","preventionTips":["Keep config key names as constants, never computed from nullable lookups","Validate properties files at startup by enumerating expected keys","Fail fast in helpers that resolve keys from maps"],"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"}