MyCATApache/Mycat-Server · error · NullPointerException
null value for
Error message
null value for ${key} What it means
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.
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).
Example fix
// before
conf.set("server.port", System.getProperty("mycat.port"));
// after
String port = System.getProperty("mycat.port", "8066");
conf.set("server.port", port); Defensive patterns
Strategy: validation
Validate before calling
if (value == null) { value = DEFAULTS.getOrDefault(key, ""); }
conf.set(key, value); Type guard
static String nonNull(String v, String def) { return v != null ? v : def; }
// conf.set(key, nonNull(rawValue, defaultValue)); Try / catch
try { conf.set(key, value); } catch (NullPointerException e) { log.warn("skipping null config value for {}", key); } Prevention
- Always supply defaults when reading env/system properties
- Filter null entries before bulk-loading configs
- Prefer getOrDefault over get for optional settings
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- null key
- bufferSize must be a power of 2
- bufferSize must not be less than 1
- can not find the data node with name
- Can't find a valid data node for specified node index
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/9e587a928b0b9ec7.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/utils/MycatPropertyConf.java:29
public MycatPropertyConf(){
}
/** Set a configuration variable. */
public MycatPropertyConf set(String key, String value) {
set(key, value, false);
return this;
}
public MycatPropertyConf set(String key, String value, boolean silent){
if (key == null) {
throw new NullPointerException("null key");
}
if (value == null) {
throw new NullPointerException("null value for " + key);
}
if (!silent) {
}
settings.put(key, value);
return this;
}
public long getSizeAsBytes(String s, long i) {
String value = (String) settings.get(s);
if(value !=null){
return byteStringAsBytes(value);
}
return i;
}
public long getSizeAsBytes(String s, String defaultValue) {View on GitHub (pinned to 65f8d8beb7)