{"record":{"id":"fd9aa894ac9abffe","repo":"mybatis/mybatis-3","slug":"cannot-get-the-value-because-the-property-fd9aa8","errorCode":null,"errorMessage":"Cannot get the value '{}' because the property '{}' is not Map, List or Array.","messagePattern":"Cannot get 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":75,"sourceCode":"      return ((Object[]) collection)[i];\n    } else if (collection instanceof char[]) {\n      return ((char[]) collection)[i];\n    } else if (collection instanceof boolean[]) {\n      return ((boolean[]) collection)[i];\n    } else if (collection instanceof byte[]) {\n      return ((byte[]) collection)[i];\n    } else if (collection instanceof double[]) {\n      return ((double[]) collection)[i];\n    } else if (collection instanceof float[]) {\n      return ((float[]) collection)[i];\n    } else if (collection instanceof int[]) {\n      return ((int[]) collection)[i];\n    } else if (collection instanceof long[]) {\n      return ((long[]) collection)[i];\n    } else if (collection instanceof short[]) {\n      return ((short[]) collection)[i];\n    } else {\n      throw new ReflectionException(\"Cannot get the value '\" + prop.getIndexedName() + \"' because the property '\"\n          + prop.getName() + \"' is not Map, List or Array.\");\n    }\n  }\n\n  protected void setCollectionValue(PropertyTokenizer prop, Object collection, Object value) {\n    if (collection == null) {\n      throw new ReflectionException(\"Cannot set the value '\" + prop.getIndexedName() + \"' because the property '\"\n          + prop.getName() + \"' is null.\");\n    }\n    if (collection instanceof Map) {\n      ((Map) collection).put(prop.getIndex(), value);\n    } else {\n      int i = Integer.parseInt(prop.getIndex());\n      if (collection instanceof List) {\n        ((List) collection).set(i, value);\n      } else if (collection instanceof Object[]) {\n        ((Object[]) collection)[i] = value;\n      } else if (collection instanceof char[]) {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/reflection/wrapper/BaseWrapper.java#L57-L93","documentation":"BaseWrapper.getCollectionValue handles Map, List, and arrays (object arrays plus all primitive arrays) as indexable collections. If the resolved property value is non-null but is none of those types, MyBatis cannot apply the '[index]' operator to it, so a ReflectionException is thrown. The index expression only works on Map (key lookup) and integer-indexed types.","triggerScenarios":"#{item[0]} where 'item' is a plain bean or String; MetaObject.getValue(\"someSet[0]\") where the property is a java.util.Set (Set is Iterable but not List, so it fails); indexing into a custom collection type that implements neither List nor Map.","commonSituations":"Switching a field from List to Set (e.g. HashSet for dedup) while mapper expressions still index it; using '[key]' syntax against a bean instead of dotted property access; parameter objects carrying custom collection implementations.","solutions":["Change the property to a List, Map, or array if you need index access","For Sets, iterate with <foreach> instead of indexing, or convert: new ArrayList<>(set)","Use dotted property names ('bean.field') for beans instead of bracket syntax","For Map-like lookup on non-standard types, expose the value through a getter (getByIndex(i))"],"exampleFix":"// before\nprivate Set<Item> items; // #{items[0]} throws\n\n// after\nprivate List<Item> items; // #{items[0]} works","handlingStrategy":"type-guard","validationCode":"Object coll = metaObject.getValue(prop);\nif (!(coll instanceof Map || coll instanceof List || coll.getClass().isArray())) {\n  // convert to List or use a different expression\n}","typeGuard":"boolean indexable(Object o) {\n  return o == null || o instanceof Map || o instanceof List || o.getClass().isArray();\n}","tryCatchPattern":"try { metaObject.getValue(\"tags[0]\"); }\ncatch (ReflectionException e) {\n  if (e.getMessage().contains(\"not Map, List or Array\")) { /* switch to foreach or convert type */ }\n  else throw e;\n}","preventionTips":["Keep indexed properties typed as List/Map/array","When changing field types, grep mappers for bracket expressions on that field","Use <foreach> for Sets and other Iterables instead of indexing"],"tags":["reflection","collections","type-mismatch","mybatis"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}