apache/cassandra · error · IllegalArgumentException

Value of %s cannot be null.

Error message

Value of %s cannot be null.

What it means

Thrown by UUIDRoleNameGenerator.enrich() when an options map passed to generate() contains a key (e.g. name_prefix, name_suffix, name_size) mapped to a null value. Prefix/suffix enrichment only accepts non-null string values, so nulls are rejected with IllegalArgumentException.

Source

Thrown at src/java/org/apache/cassandra/db/guardrails/UUIDRoleNameGenerator.java:132

    @Override
    public void validateParameters() throws ConfigurationException
    {
        if (minimumNameSize < DEFAULT_MINIMUM_NAME_SIZE || minimumNameSize > MAXIMUM_NAME_SIZE)
            throw new ConfigurationException(MINIMUM_NAME_SIZE_CONFIG_OPTION + " has to be at least " + DEFAULT_MINIMUM_NAME_SIZE + " and at most " + MAXIMUM_NAME_SIZE);
    }

    private String enrich(String key, String generatedValue, Map<String, Object> options)
    {
        if (options == null || options.isEmpty())
            return generatedValue;

        if (options.containsKey(key))
        {
            Object value = options.get(key);

            if (value == null)
                throw new IllegalArgumentException("Value of " + key + " cannot be null.");

            if (!(value instanceof String))
                throw new IllegalArgumentException("Value of " + key + " is not a string.");

            if (NAME_PREFIX_KEY.equals(key))
                generatedValue = value + generatedValue;
            else if (NAME_SUFFIX_KEY.equals(key))
                generatedValue = generatedValue + value;
        }

        return generatedValue;
    }

    private int getSize(Map<String, Object> options)
    {
        Object sizeObject;
        if (options == null)
        {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Remove null-valued keys from the options map before calling generate
  2. Default empty prefix/suffix to "" instead of null in your config layer
  3. Check the message for the offending key name and provide a string value for it

Example fix

// before
Map<String,Object> options = new HashMap<>();
options.put("name_prefix", null);
// after
Map<String,Object> options = new HashMap<>();
options.put("name_prefix", "svc-");
Defensive patterns

Strategy: type-guard

Validate before calling

for (var e : options.entrySet())
    if (e.getValue() == null)
        throw new IllegalArgumentException("null value for option: " + e.getKey());

Type guard

boolean hasNonNullStringValues(Map<String,Object> options) {
    return options.values().stream().allMatch(v -> v instanceof String);
}

Try / catch

try {
    String name = generator.generate(options);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("cannot be null")) {
        // drop null-valued keys or substitute defaults, then retry
    } else throw e;
}

Prevention

When it happens

Trigger: Calling generate(options) with a map built programmatically that includes a key with a null value, e.g. options.put("name_prefix", null), typically from unmarshalled config where a key exists but has no value.

Common situations: YAML/JSON config with 'name_prefix:' but no value deserialized as null; templating systems substituting an unset variable with null.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/9fb0e7121ce16d76. Report an issue: GitHub.