apache/dubbo · error · IllegalArgumentException

pns.length != pvs.length

Error message

pns.length != pvs.length

What it means

Thrown by Wrapper.setPropertyValues when the property-name array and property-value array have different lengths. The method pairs them index-by-index, so a length mismatch is treated as a caller programming error.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java:490

            throws NoSuchPropertyException, IllegalArgumentException {
        Object[] ret = new Object[pns.length];
        for (int i = 0; i < ret.length; i++) {
            ret[i] = getPropertyValue(instance, pns[i]);
        }
        return ret;
    }

    /**
     * set property value.
     *
     * @param instance instance.
     * @param pns      property name array.
     * @param pvs      property value array.
     */
    public void setPropertyValues(Object instance, String[] pns, Object[] pvs)
            throws NoSuchPropertyException, IllegalArgumentException {
        if (pns.length != pvs.length) {
            throw new IllegalArgumentException("pns.length != pvs.length");
        }

        for (int i = 0; i < pns.length; i++) {
            setPropertyValue(instance, pns[i], pvs[i]);
        }
    }

    /**
     * get method name array.
     *
     * @return method name array.
     */
    public abstract String[] getMethodNames();

    /**
     * get method name array.
     *
     * @return method name array.

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Ensure pns and pvs are built from the same source (e.g. iterate a Map's entrySet once) so lengths stay equal.
  2. Add an assertion pns.length == pvs.length before calling setPropertyValues.
  3. If you genuinely have partial data, align the arrays or use single-property setPropertyValue calls in a loop.

Example fix

// before
String[] pns = {"a","b"};
Object[] pvs = {"x"};
wrapper.setPropertyValues(obj, pns, pvs);
// after
assert pns.length == pvs.length;
wrapper.setPropertyValues(obj, pns, pvs);
Defensive patterns

Strategy: validation

Validate before calling

if (pns == null || pvs == null || pns.length != pvs.length) {
    throw new IllegalArgumentException("name/value length mismatch");
}
wrapper.setPropertyValues(instance, pns, pvs);

Type guard

static boolean arraysAligned(String[] pns, Object[] pvs) {
    return pns != null && pvs != null && pns.length == pvs.length;
}

Try / catch

try {
    wrapper.setPropertyValues(instance, pns, pvs);
} catch (IllegalArgumentException e) {
    // length mismatch; rebuild arrays from a single source
}

Prevention

When it happens

Trigger: Calling wrapper.setPropertyValues(instance, pns, pvs) where pns.length != pvs.length. Common in batch property population code (e.g. deserializing a struct into a POJO) that builds the two arrays independently and gets out of sync.

Common situations: A deserializer or RPC argument assembler constructs the name and value arrays in separate loops and one loop drops or duplicates an entry. Also seen after editing a DTO where a field was added to one side but not the other.

Related errors


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