{"record":{"id":"5f0e997527efd559","repo":"spring-projects/spring-ai","slug":"expected-a-list-but-got","errorCode":null,"errorMessage":"Expected a List, but got: ","messagePattern":"Expected a List, but got: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorFilterExpressionConverter.java","lineNumber":83,"sourceCode":"\t\telse {\n\t\t\tthis.convertOperand(expression.left(), context);\n\t\t\tcontext.append(getOperationSymbol(expression));\n\t\t\tthis.convertOperand(expression.right(), context);\n\t\t}\n\t}\n\n\tprivate void handleIn(Expression expression, StringBuilder context) {\n\t\tcontext.append(\"(\");\n\t\tconvertToConditions(expression, context);\n\t\tcontext.append(\")\");\n\t}\n\n\tprivate void convertToConditions(Expression expression, StringBuilder context) {\n\t\tAssert.state(expression.right() != null, \"expression should have a right operand\");\n\t\tFilter.Value right = (Filter.Value) expression.right();\n\t\tObject value = right.value();\n\t\tif (!(value instanceof List)) {\n\t\t\tthrow new IllegalArgumentException(\"Expected a List, but got: \" + value.getClass().getSimpleName());\n\t\t}\n\t\tList<Object> values = (List) value;\n\t\tfor (int i = 0; i < values.size(); i++) {\n\t\t\tthis.convertOperand(expression.left(), context);\n\t\t\tcontext.append(\" == \");\n\t\t\tthis.doSingleValue(normalizeDateString(values.get(i)), context);\n\t\t\tif (i < values.size() - 1) {\n\t\t\t\tcontext.append(\" || \");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void handleNotIn(Expression expression, StringBuilder context) {\n\t\tcontext.append(\"!(\");\n\t\tconvertToConditions(expression, context);\n\t\tcontext.append(\")\");\n\t}\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorFilterExpressionConverter.java#L65-L101","documentation":"PgVectorFilterExpressionConverter.convertToConditions only supports IN/NOTIN (NIN) filter expressions whose right operand is a Filter.Value wrapping a java.util.List. If the right side is a single value (e.g. Filter.eq-style value passed where an IN was expected, or a non-collection value), the cast to List would fail, so the converter throws this IllegalArgumentException up front.","triggerScenarios":"Building a PgVectorStore filter like Filter.in(\"country\", ...) indirectly but with a single non-List value on the right side — e.g. using Filter.in with a scalar, or a custom Expression whose right() is a Value holding a String/Number instead of a List.","commonSituations":"Hand-constructing Filter.Expression trees instead of using the Filter expression DSL; migrating filters from another vector store whose converter accepted scalars for IN; a typo where eq was intended but in semantics got built.","solutions":["Wrap the right-hand operand in a List: Filter.in(\"country\", List.of(\"US\",\"DE\")) instead of a single value.","Use Filter.eq / Filter.ne for single-value comparisons instead of in/nin.","Check the Filter.Expression you built: expression.right() must be a Filter.Value whose value() instanceof List."],"exampleFix":"// before\nExpression e = new Expression(IN, \"country\", new Value(\"US\"));\n// after\nExpression e = new Expression(IN, \"country\", new Value(List.of(\"US\", \"DE\")));","handlingStrategy":"validation","validationCode":"if (!(expr instanceof Filter.Expression fe && fe.right() instanceof Filter.Value v && v.value() instanceof List)) {\n    throw new IllegalArgumentException(\"IN/NIN requires a List value\");\n}","typeGuard":"static boolean isInWithListValue(Expression e) {\n    return e instanceof Filter.Expression fe\n        && fe.right() instanceof Filter.Value v\n        && v.value() instanceof List<?>;\n}","tryCatchPattern":"try {\n    String sql = converter.convertExpression(expr);\n} catch (IllegalArgumentException e) {\n    // log offending expression; fix filter construction\n}","preventionTips":["Always use Filter.in(key, List.of(...)) with a collection.","Use eq/ne for single values rather than in with scalars.","Unit-test custom Filter.Expression trees before production use."],"tags":["filter-expression","pgvector","illegal-argument"],"backgroundTag":"type-mismatch","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}