{"record":{"id":"ed0ad32a3ab66e61","repo":"apache/dubbo","slug":"pns-length-pvs-length","errorCode":null,"errorMessage":"pns.length != pvs.length","messagePattern":"pns\\.length != pvs\\.length","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java","lineNumber":490,"sourceCode":"            throws NoSuchPropertyException, IllegalArgumentException {\n        Object[] ret = new Object[pns.length];\n        for (int i = 0; i < ret.length; i++) {\n            ret[i] = getPropertyValue(instance, pns[i]);\n        }\n        return ret;\n    }\n\n    /**\n     * set property value.\n     *\n     * @param instance instance.\n     * @param pns      property name array.\n     * @param pvs      property value array.\n     */\n    public void setPropertyValues(Object instance, String[] pns, Object[] pvs)\n            throws NoSuchPropertyException, IllegalArgumentException {\n        if (pns.length != pvs.length) {\n            throw new IllegalArgumentException(\"pns.length != pvs.length\");\n        }\n\n        for (int i = 0; i < pns.length; i++) {\n            setPropertyValue(instance, pns[i], pvs[i]);\n        }\n    }\n\n    /**\n     * get method name array.\n     *\n     * @return method name array.\n     */\n    public abstract String[] getMethodNames();\n\n    /**\n     * get method name array.\n     *\n     * @return method name array.","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java#L472-L508","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure pns and pvs are built from the same source (e.g. iterate a Map's entrySet once) so lengths stay equal.","Add an assertion pns.length == pvs.length before calling setPropertyValues.","If you genuinely have partial data, align the arrays or use single-property setPropertyValue calls in a loop."],"exampleFix":"// before\nString[] pns = {\"a\",\"b\"};\nObject[] pvs = {\"x\"};\nwrapper.setPropertyValues(obj, pns, pvs);\n// after\nassert pns.length == pvs.length;\nwrapper.setPropertyValues(obj, pns, pvs);","handlingStrategy":"validation","validationCode":"if (pns == null || pvs == null || pns.length != pvs.length) {\n    throw new IllegalArgumentException(\"name/value length mismatch\");\n}\nwrapper.setPropertyValues(instance, pns, pvs);","typeGuard":"static boolean arraysAligned(String[] pns, Object[] pvs) {\n    return pns != null && pvs != null && pns.length == pvs.length;\n}","tryCatchPattern":"try {\n    wrapper.setPropertyValues(instance, pns, pvs);\n} catch (IllegalArgumentException e) {\n    // length mismatch; rebuild arrays from a single source\n}","preventionTips":["Build name and value arrays from the same iteration (e.g. Map.entrySet) to keep them aligned.","Assert pns.length == pvs.length before calling setPropertyValues.","Add unit tests that exercise batch property population."],"tags":["reflection","wrapper","property","validation","argument-mismatch"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}