{"record":{"id":"9148bfde6ce97e15","repo":"xai-org/x-algorithm","slug":"count-expects-input-of-string-map-or-collection-t","errorCode":null,"errorMessage":"Count expects input of String, Map or Collection types but %s received","messagePattern":"Count expects input of String, Map or Collection types but (.+?) received","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/collection/Count.java","lineNumber":42,"sourceCode":"    examples = {\n        \"Count(ToSet(List(1, 2, 3)))\"\n    }\n)\npublic class Count extends FunctionNode1<Runtime, Object> {\n  private static final Signature SIGNATURE = new Signature(\n      ImmutableList.of(Type.OBJECT),\n      Type.LONG\n  );\n\n  public Count(String exprText, ImmutableList<ASTNode> children) throws SemanticCheckFailure {\n    super(exprText, children);\n\n    Class<?> typeBase = children.get(0).getReturnType().typeBase;\n    if (!Object.class.equals(typeBase)\n        && !String.class.equals(typeBase)\n        && !Collection.class.isAssignableFrom(typeBase)\n        && !Map.class.isAssignableFrom(typeBase)) {\n      throw new SemanticCheckFailure(String.format(\n          \"Count expects input of String, Map or Collection types but %s received\",\n          typeBase.getName()));\n    }\n\n  }\n\n  @Override\n  public Signature getSignature() {\n    return SIGNATURE;\n  }\n\n  @Override\n  protected CacheLevel getCacheLevel() {\n    return CacheLevel.Global;\n  }\n\n  @Override\n  @SuppressWarnings(\"unchecked\")","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/collection/Count.java#L24-L60","documentation":"Count() accepts a first argument whose static typeBase is Object, String, Collection, or Map. Any other type (Long, Boolean, StructTuple, Pair, etc.) fails semantic checking with this message. Count measures length/size of strings, collections and maps, so scalars are rejected.","triggerScenarios":"Calling Count(42), Count(true), Count(pair), or chaining Count onto a function that returns a scalar.","commonSituations":"Nesting Count(Count(x)), assuming Count is an identity/counting helper for scalars, or a pipeline refactor that changed the input type.","solutions":["Pass a String, Collection, or Map expression to Count","If the value may be untyped, ensure its type is Object so the generic path applies","Use the scalar directly instead of Count for non-sized values"],"exampleFix":"// before\nCount(Count(items))\n// after\nCount(items)","handlingStrategy":"type-guard","validationCode":"// rule-language: only count sized values\nIf(IsString(x), Count(x), If(IsCollection(x), Count(x), 1))","typeGuard":"// host code\nClass<?> base = children.get(0).getReturnType().typeBase;\nboolean ok = Object.class.equals(base) || String.class.equals(base)\n    || Collection.class.isAssignableFrom(base) || Map.class.isAssignableFrom(base);","tryCatchPattern":null,"preventionTips":["Pass only String/Collection/Map to Count","Don't nest Count over scalar-returning functions"],"tags":["botmaker","semantic-check","type-mismatch","count"],"backgroundTag":"function-argument-type-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}