apache/shardingsphere · warning · InvalidVariableValueException

12011

12011

Error message

Invalid variable value '%s'.

What it means

InvalidVariableValueException (error code 12011) thrown by SetDistVariableExecutor.getValue when the raw string value cannot be converted to the property's declared type: TypedPropertyValue(propertyKey, value) raises TypedPropertyValueException (caught and ignored), which is rethrown as this exception. A second source is checkProxyMetaDataCollectorCron: for TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_CRON the value must be non-empty AND a valid Quartz CronExpression.

Source

Thrown at proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutor.java:79

    private void handleConfigurationProperty(final ContextManager contextManager, final TypedPropertyKey propertyKey, final String value) {
        MetaDataContexts metaDataContexts = contextManager.getMetaDataContexts();
        Properties props = new Properties();
        props.putAll(metaDataContexts.getMetaData().getProps().getProps());
        props.putAll(metaDataContexts.getMetaData().getTemporaryProps().getProps());
        props.put(propertyKey.getKey(), getValue(propertyKey, value));
        contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService().alterProperties(props);
    }
    
    private Object getValue(final TypedPropertyKey propertyKey, final String value) {
        try {
            Object propertyValue = new TypedPropertyValue(propertyKey, value).getValue();
            checkProxyMetaDataCollectorCron(propertyKey, value);
            if (Enum.class.isAssignableFrom(propertyKey.getType())) {
                return propertyValue.toString();
            }
            return TypedSPI.class.isAssignableFrom(propertyKey.getType()) ? ((TypedSPI) propertyValue).getType().toString() : propertyValue;
        } catch (final TypedPropertyValueException ignored) {
            throw new InvalidVariableValueException(value);
        }
    }
    
    private void checkProxyMetaDataCollectorCron(final TypedPropertyKey propertyKey, final String value) {
        if (TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_CRON == propertyKey) {
            ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(value) && CronExpression.isValidExpression(value), () -> new InvalidVariableValueException(value));
        }
    }
    
    @Override
    public Class<SetDistVariableStatement> getType() {
        return SetDistVariableStatement.class;
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Supply a value matching the key's type: plain int/long/boolean for numeric/flag keys, exact enum/SPI type names for typed keys
  2. For proxy_meta_data_collector_cron use a valid Quartz cron expression (e.g. '0/5 * * * * ?'), not Unix 5-field cron, and never empty
  3. Consult the property key's documented data type before setting, and remove quotes only as the grammar requires

Example fix

-- before
SET DIST VARIABLE WHERE NAME = 'proxy_meta_data_collector_cron' AND VALUE = '*/5 * * * *';

-- after
SET DIST VARIABLE WHERE NAME = 'proxy_meta_data_collector_cron' AND VALUE = '0/5 * * * * ?';
Defensive patterns

Strategy: validation

Validate before calling

public void validateValue(final TypedPropertyKey key, final String value) {
    try {
        new TypedPropertyValue(key, value);
    } catch (final TypedPropertyValueException ex) {
        throw new IllegalArgumentException("Value '" + value + "' does not match type of " + key.getKey());
    }
    if (TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_CRON == key
            && !CronExpression.isValidExpression(value)) {
        throw new IllegalArgumentException("Value must be a valid Quartz cron: " + value);
    }
}

Prevention

When it happens

Trigger: SET DIST VARIABLE with a value that fails typed conversion, e.g. NAME='max-connections-size-per-query', VALUE='abc' (not an int), or an enum/SPI-typed key given an unknown constant; or NAME='proxy_meta_data_collector_cron' with a malformed/empty cron string that CronExpression.isValidExpression rejects.

Common situations: Passing quoted numerics with stray characters or wrong units; assuming cron formats from other schedulers (5-field Unix cron) are accepted when Quartz 6/7-field expressions are required; copy-pasting property values between incompatible keys.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/b3ea840ed997ea29. Report an issue: GitHub.