apache/dubbo · error · IllegalArgumentException

the array size of values should be larger than 0

Error message

the array size of values should be larger than 0

What it means

Thrown by the FixedParamValue constructor when called with a zero-length varargs array. FixedParamValue represents a param key whose allowed value set is fixed and enumerated up front (e.g. boolean-style keys). At least one permitted value must be supplied so getN/getIndex have a valid index 0 to work with.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/url/component/param/FixedParamValue.java:34

 */
package org.apache.dubbo.common.url.component.param;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * In lower case
 */
public class FixedParamValue implements ParamValue {
    private final String[] values;
    private final Map<String, Integer> val2Index;

    public FixedParamValue(String... values) {
        if (values.length == 0) {
            throw new IllegalArgumentException("the array size of values should be larger than 0");
        }
        this.values = values;
        Map<String, Integer> valueMap = new HashMap<>(values.length);
        for (int i = 0; i < values.length; i++) {
            if (values[i] != null) {
                valueMap.put(values[i].toLowerCase(Locale.ROOT), i);
            }
        }
        val2Index = Collections.unmodifiableMap(valueMap);
    }

    /**
     * DEFAULT value will be returned if n = 0
     * @param n
     */
    @Override
    public String getN(int n) {
        return values[n];

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Pass at least one permitted value string to the FixedParamValue constructor.
  2. If the value set is genuinely open/unbounded, use DynamicValues instead of FixedParamValue.
  3. Check the DynamicParamSource extension code that builds the ParamValue list and ensure no empty arrays slip in.

Example fix

// before
new FixedParamValue(); // throws: no values
new FixedParamValue(new String[0]);

// after
new FixedParamValue("true", "false");
// or for an open value set:
new DynamicValues(null);
Defensive patterns

Strategy: validation

Validate before calling

String[] vals = /* ... */;
if (vals == null || vals.length == 0) {
    throw new IllegalArgumentException("FixedParamValue requires >= 1 value; use DynamicValues for open sets");
}
new FixedParamValue(vals);

Type guard

static boolean nonEmptyValues(String[] vals) {
    return vals != null && vals.length > 0;
}

Prevention

When it happens

Trigger: new FixedParamValue() or new FixedParamValue(new String[0]) — constructing the fixed value set with no entries. This is an internal SPI class instantiated by DynamicParamSource extensions when declaring known param keys.

Common situations: A custom DynamicParamSource extension declares a fixed param key but passes an empty values array (e.g. reads values from a config that resolved empty, or a code bug). End users do not normally instantiate this class directly.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/5698ed23adca250a. Report an issue: GitHub.