{"record":{"id":"b39a9d9b67297485","repo":"xai-org/x-algorithm","slug":"collection-is-empty-b39a9d","errorCode":null,"errorMessage":"collection is empty","messagePattern":"collection is empty","errorType":"validation","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/math/Min.java","lineNumber":58,"sourceCode":"  public Signature getSignature() {\n    return SIGNATURE;\n  }\n\n  @Override\n  protected CacheLevel getCacheLevel() {\n    return CacheLevel.Global;\n  }\n\n  @Override\n  protected Object apply(Context<Runtime> context, List<Number> numbers) {\n    Number min = null;\n    for (Number num : numbers) {\n      if (min == null || num.doubleValue() < min.doubleValue()) {\n        min = num;\n      }\n    }\n    if (min == null) {\n      throw new NoSuchElementException(\"collection is empty\");\n    }\n    return min;\n  }\n}\n","sourceCodeStart":40,"sourceCodeEnd":63,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/math/Min.java#L40-L63","documentation":"Min.apply throws NoSuchElementException(\"collection is empty\") when the input collection is empty, since min stays null after iterating. Same semantics as Max and standard empty-aggregate behavior.","triggerScenarios":"Calling Min() with an empty collection: Min().apply(ctx, ImmutableList.of()), or an expression computing a minimum over an empty window/group.","commonSituations":"Empty time windows, empty filter results, optional/nullable lists evaluated to empty, off-by-one range boundaries.","solutions":["Guard with an emptiness check and supply a default (e.g. If(IsEmpty(list), default, Min(list)))","Ensure upstream filters/windows guarantee at least one element","Catch NoSuchElementException only as a last resort at pipeline level"],"exampleFix":"// before\nNumber m = Min().apply(ctx, numbers); // empty -> NoSuchElementException\n// after\nNumber m = numbers.isEmpty() ? Double.MAX_VALUE : (Number) Min().apply(ctx, numbers);\n","handlingStrategy":"validation","validationCode":"if (numbers == null || numbers.isEmpty()) {\n  return DEFAULT_VALUE;\n}\nreturn Min().apply(ctx, numbers);","typeGuard":"public static boolean nonEmpty(Collection<?> c) { return c != null && !c.isEmpty(); }","tryCatchPattern":"try {\n  return (Number) Min().apply(ctx, numbers);\n} catch (NoSuchElementException e) {\n  return emptyDefault;\n}","preventionTips":["Guard aggregates with If(IsEmpty(list), default, Min(list)) in expressions","Validate window/group boundaries so ranges contain at least one row","Treat empty-collection aggregation as an explicit business case, not an error"],"tags":["math","min","empty-collection","aggregation"],"backgroundTag":"aggregate-on-empty-collection","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}