{"record":{"id":"6ee5689deb932dc7","repo":"xai-org/x-algorithm","slug":"expecting-the-input-to-be-of-string-or-list-type-b","errorCode":null,"errorMessage":"expecting the input to be of String or List type but received: %s for %s","messagePattern":"expecting the input to be of String or List type but received: (.+?) for (.+?)","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/collection/Slice.java","lineNumber":68,"sourceCode":"    return SIGNATURE;\n  }\n\n  @Override\n  protected CacheLevel getCacheLevel() {\n    return CacheLevel.Global;\n  }\n\n  public Slice(String exprText, ImmutableList<ASTNode> children) throws SemanticCheckFailure {\n    super(exprText, validateType(children));\n  }\n\n  private static ImmutableList<ASTNode> validateType(ImmutableList<ASTNode> children)\n      throws SemanticCheckFailure {\n    Class<?> inputType = children.get(0).getReturnType().typeBase;\n    if (!Object.class.equals(inputType)\n      && !String.class.equals(inputType)\n      && !List.class.equals(inputType)) {\n      throw new SemanticCheckFailure(mkErrorMessage(inputType));\n    }\n    return children;\n  }\n\n  @Override\n  protected Object apply(\n      Context<Runtime> context, Object input, Long beginIndex, Long endIndex) {\n    if (input instanceof String) {\n      return ((String) input).substring(beginIndex.intValue(), endIndex.intValue());\n    } else if (input instanceof List) {\n      return Collections.unmodifiableList(new ArrayList<>(\n          ((List) input).subList(beginIndex.intValue(), endIndex.intValue())));\n    } else {\n      throw new IllegalArgumentException(mkErrorMessage(input.getClass()));\n    }\n  }\n\n  @Override","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/collection/Slice.java#L50-L86","documentation":"Slice()'s semantic validation requires the first argument's static typeBase to be Object, String, or List. Other types (Map, Set, Long, etc.) fail at build time with this message, which includes the offending type and the expression text.","triggerScenarios":"Calling Slice(myMap, 0, 1), Slice(someSet, 0, 1), or Slice(42, 0, 1) at rule-build time.","commonSituations":"Assuming Slice works on any collection; refactoring input from List to Set/Map without updating the Slice call.","solutions":["Convert to a List first (e.g. ToList/Set-to-list conversion) before slicing","Use ToSet+Contains or map accessors for Maps/Sets instead of Slice","Verify the first argument's return type is List or String"],"exampleFix":"// before\nSlice(mySet, 0, 2)\n// after\nSlice(ToList(mySet), 0, 2)","handlingStrategy":"type-guard","validationCode":"// rule-language: convert before slicing\nSlice(ToList(setVal), 0, 2)","typeGuard":"// host code\nClass<?> base = children.get(0).getReturnType().typeBase;\nboolean ok = Object.class.equals(base) || String.class.equals(base) || List.class.equals(base);","tryCatchPattern":null,"preventionTips":["Slice only Strings and Lists","Convert Sets/Maps to Lists first"],"tags":["botmaker","semantic-check","type-mismatch","slice"],"backgroundTag":"function-argument-type-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}