MyCATApache/Mycat-Server · error · NullPointerException

null key

Error message

null key

What it means

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.

Solutions

  1. Ensure the key is a non-null String before calling set; check the source of the key variable.
  2. Fix Map.get()/getProperty() call sites to handle missing keys instead of passing null through.
  3. Swap arguments if key and value were accidentally reversed (though here the key itself is null).
  4. Wrap config assembly in a helper that asserts non-null keys and throws a descriptive IllegalArgumentException.

Example fix

// before
String key = props.get("thread.count"); // may be null
conf.set(key, "8");
// after
String key = props.get("thread.count");
if (key != null) conf.set(key, "8");
Defensive patterns

Strategy: type-guard

Validate before calling

if (key == null) throw new IllegalArgumentException("config key must not be null");
conf.set(key, value);

Type guard

static String requireKey(String k) { if (k == null) throw new IllegalArgumentException("null config key"); return k; }
// conf.set(requireKey(k), v);

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/63b76dfb453c1586. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/memory/unsafe/utils/MycatPropertyConf.java:26

public class MycatPropertyConf {

    private ConcurrentHashMap settings = new ConcurrentHashMap<String, String>();

    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;

View on GitHub (pinned to 65f8d8beb7)