{"record":{"id":"6a8c6e77d3f2e96b","repo":"mybatis/mybatis-3","slug":"cannot-set-the-value-because-the-property-6a8c6e","errorCode":null,"errorMessage":"Cannot set the value '{}' because the property '{}' is not Map, List or Array.","messagePattern":"Cannot set the value '(.+?)' because the property '(.+?)' is not Map, List or Array\\.","errorType":"exception","errorClass":"ReflectionException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/reflection/wrapper/BaseWrapper.java","lineNumber":110,"sourceCode":"        ((Object[]) collection)[i] = value;\n      } else if (collection instanceof char[]) {\n        ((char[]) collection)[i] = (Character) value;\n      } else if (collection instanceof boolean[]) {\n        ((boolean[]) collection)[i] = (Boolean) value;\n      } else if (collection instanceof byte[]) {\n        ((byte[]) collection)[i] = (Byte) value;\n      } else if (collection instanceof double[]) {\n        ((double[]) collection)[i] = (Double) value;\n      } else if (collection instanceof float[]) {\n        ((float[]) collection)[i] = (Float) value;\n      } else if (collection instanceof int[]) {\n        ((int[]) collection)[i] = (Integer) value;\n      } else if (collection instanceof long[]) {\n        ((long[]) collection)[i] = (Long) value;\n      } else if (collection instanceof short[]) {\n        ((short[]) collection)[i] = (Short) value;\n      } else {\n        throw new ReflectionException(\"Cannot set the value '\" + prop.getIndexedName() + \"' because the property '\"\n            + prop.getName() + \"' is not Map, List or Array.\");\n      }\n    }\n  }\n\n  protected Object getChildValue(PropertyTokenizer prop) {\n    MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());\n    if (metaValue == SystemMetaObject.NULL_META_OBJECT) {\n      return null;\n    }\n    return metaValue.getValue(prop.getChildren());\n  }\n\n  protected void setChildValue(PropertyTokenizer prop, Object value) {\n    MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());\n    if (metaValue == SystemMetaObject.NULL_META_OBJECT) {\n      if (value == null) {\n        // don't instantiate child path if value is null","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/reflection/wrapper/BaseWrapper.java#L92-L128","documentation":"The set-side counterpart of the unsupported-collection-type read error: BaseWrapper.setCollectionValue only assigns into Map, List and object/primitive arrays. Setting 'prop[i] = value' on any other non-null type (a bean, String, Set, custom collection) throws a ReflectionException because no indexed write semantics exist for that type.","triggerScenarios":"MetaObject.setValue(\"tags[0]\", v) where 'tags' is a java.util.Set; result mapping writing indexed elements into a custom collection class; attempting 'str[0] = c' style writes through the reflection wrapper on non-array types.","commonSituations":"Bean field type changed from List to Set or a custom collection while indexed write paths (resultMaps, generic copiers built on MetaObject) were not updated.","solutions":["Use a List, Map, or array as the target type for indexed writes","For Sets, write the whole collection (setValue(\"tags\", setWithNewElement)) or switch the field to List","Update resultMap <collection> mappings when the property type changes to a non-indexable type"],"exampleFix":"// before\nprivate Set<String> tags; // setValue(\"tags[0]\", s) throws\n\n// after\nprivate List<String> tags; // setValue(\"tags[0]\", s) works","handlingStrategy":"type-guard","validationCode":"Object target = metaObject.getValue(\"tags\");\nif (!(target instanceof Map || target instanceof List || target.getClass().isArray())) {\n  metaObject.setValue(\"tags\", new java.util.ArrayList<>(/* seed */)); // replace with indexable type\n}","typeGuard":"boolean writableIndexed(Object o) {\n  return o instanceof Map || o instanceof List || o.getClass().isArray();\n}","tryCatchPattern":null,"preventionTips":["Design beans whose properties receive indexed writes as List/Map/array only","When introducing Sets or custom collections, update all indexed write paths","Prefer whole-collection assignment (setValue(\"tags\", newValue)) for non-indexable types"],"tags":["reflection","collections","type-mismatch","mybatis"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}