Skip to content

Validate BotMaker collection function inputs - #62

Open
exocognosis wants to merge 1 commit into
xai-org:mainfrom
exocognosis:agent/validate-botmaker-collection-inputs
Open

Validate BotMaker collection function inputs#62
exocognosis wants to merge 1 commit into
xai-org:mainfrom
exocognosis:agent/validate-botmaker-collection-inputs

Conversation

@exocognosis

Copy link
Copy Markdown

Summary

  • Reject an empty list in First() with a clear IllegalArgumentException.
  • Clamp the FirstN() count to the valid range from zero through the list size.
  • Validate every Slice() range before calling substring() or subList().
  • Document the new boundary behavior in each function definition.

Problem

The collection functions passed unchecked values to Java APIs. This exposed implementation exceptions such as IndexOutOfBoundsException and IllegalArgumentException without BotMaker-specific context. FirstN() also converted a Long to an int before it applied bounds. Large values could therefore wrap before validation.

Solution

First() now detects an empty list before it reads index zero. It reports that the function requires a non-empty list.

FirstN() now clamps the requested count while it is still a long. A negative count returns an empty view. A count greater than the list size returns the full list. This also handles Long.MIN_VALUE and Long.MAX_VALUE without integer wraparound.

Slice() now checks that the start index is non-negative, the end index is not less than the start index, and the end index does not exceed the input length. The check runs before either index is converted to an int. Invalid string and list ranges now produce the same error format with the requested range and input length.

Validation

  • Ran git diff --check.
  • Ran direct Java boundary checks for negative, zero, in-range, oversized, Long.MIN_VALUE, and Long.MAX_VALUE counts.
  • Ran direct Java boundary checks for negative bounds, reversed bounds, oversized bounds, empty ranges, and valid ranges.

The public repository snapshot does not include a root build workspace or an externally resolvable BotMaker dependency graph. A complete BotMaker target build is therefore not available from this checkout.

Fixes #58

@exocognosis
exocognosis marked this pull request as ready for review August 15, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BotMaker collection functions crash on edge cases: missing validation for empty lists and invalid indices

1 participant