Skip to content

Aggregation Array OOB Error#20204

Merged
sandeshkr419 merged 13 commits intoopensearch-project:mainfrom
ajleong623:aggregation-array-oob
Dec 11, 2025
Merged

Aggregation Array OOB Error#20204
sandeshkr419 merged 13 commits intoopensearch-project:mainfrom
ajleong623:aggregation-array-oob

Conversation

@ajleong623
Copy link
Copy Markdown
Contributor

@ajleong623 ajleong623 commented Dec 9, 2025

Description

In Ranges.java, the comparator attribute is static which means that every time a new Ranges method is created, the comparator is overridden. This leads to the OOB error because the wrong array comparator might used for the wrong array length if there are multiple aggregations.

Related Issues

Resolves #19365

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an array out-of-bounds error during aggregation operations.
  • Tests

    • Added coverage for date-histogram plus numeric-range aggregation scenarios and adjusted a test expectation for overall search counts.
  • Refactor

    • Simplified range-aggregation utilities by converting several helpers to instance-level usage to improve clarity and stability.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 9, 2025

Walkthrough

Refactors Ranges from static to instance methods, updates callers, adds an integration test reproducing a date-histogram + unsigned_long range aggregation scenario, and updates release notes to document the fix for an array-out-of-bounds during aggregation.

Changes

Cohort / File(s) Summary
Test Addition
client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java
Added testSearchWithDateAndRangeAgg() with index setup for date_created (date) and distribution.number_events (unsigned_long); adjusted testCountAllIndicesNoQuery() expected count.
Ranges Refactor
server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/Ranges.java
Converted comparator and utility methods (compareByteValue, withinLowerBound, withinUpperBound) from static to instance members; comparator initialized in constructor.
Caller Update
server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/rangecollector/AbstractRangeCollector.java
Replaced static calls to Ranges.withinLowerBound/withinUpperBound with instance calls on the existing ranges object.
Release Notes
release-notes/opensearch.release-notes-3.4.0.md
Fixed typos and formatting; added entry for "Fix array out of bounds during aggregation" and attached PR reference(s).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review areas requiring attention:
    • Ranges.java — verify comparator initialization and thread-safety if instances are shared.
    • Call sites beyond AbstractRangeCollector — search for any remaining static usages.
    • New test SearchIT.testSearchWithDateAndRangeAgg() — confirm index setup and assertions match intended reproducer.

Possibly related PRs

Suggested reviewers

  • msfroh
  • reta
  • sachinpkale
  • shwetathareja
  • andrross
  • dbwiddis

Poem

"I hopped through bytes and bounds today,
Swapped statics for instances, paved the way,
Yearly buckets bloom, ranges fall in line,
No more rogue indexes — the results are fine! 🐇"

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Aggregation Array OOB Error' directly summarizes the main change: fixing an array out-of-bounds error in aggregations by converting a static comparator to instance field in Ranges.java.
Linked Issues check ✅ Passed The PR successfully addresses issue #19365 by converting the static comparator to an instance field, preventing overwrites when multiple Ranges objects are created. A new test case testSearchWithDateAndRangeAgg was added to verify the fix with date and range aggregations on unsigned_long fields.
Out of Scope Changes check ✅ Passed The PR includes release notes updates (typo fix for 'unsigned_long' and formatting) that are tangential to the core fix. However, these are minor presentation changes and reasonable within scope for a bug fix release.
Description check ✅ Passed The pull request description clearly explains the bug (static comparator being overridden), references the related issue #19365, and includes all required checklist items marked as complete.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added bug Something isn't working Search:Aggregations labels Dec 9, 2025
@ajleong623 ajleong623 changed the title Aggregation Array OOB error Aggregation Array OOB Error Dec 9, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 9, 2025

✅ Gradle check result for 5eb3203: SUCCESS

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.26%. Comparing base (1aed472) to head (d90d6a9).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #20204      +/-   ##
============================================
- Coverage     73.29%   73.26%   -0.03%     
+ Complexity    71780    71757      -23     
============================================
  Files          5795     5795              
  Lines        328297   328297              
  Branches      47282    47282              
============================================
- Hits         240612   240519      -93     
- Misses        68368    68464      +96     
+ Partials      19317    19314       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sandeshkr419
Copy link
Copy Markdown
Member

Nice catch @ajleong623 - thanks for finding & fixing it.

Can you add up a quick test case as well to verify the same - before and after your change!

Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 7895552: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 3b8467c: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@sandeshkr419
Copy link
Copy Markdown
Member

@ajleong623 Gentle nudge that we could make this bug fix to 3.4 if we can merge it this week.

Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for a2090dd: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for d90d6a9: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Copy Markdown
Contributor

✅ Gradle check result for d90d6a9: SUCCESS

@sandeshkr419 sandeshkr419 merged commit 947efd3 into opensearch-project:main Dec 11, 2025
94 of 136 checks passed
@sandeshkr419 sandeshkr419 added backport 3.4 Backport to 3.4 branch and removed backport 3.4 Backport to 3.4 branch labels Dec 12, 2025
@prudhvigodithi prudhvigodithi added backport 3.4 Backport to 3.4 branch and removed backport 3.4 Backport to 3.4 branch labels Dec 12, 2025
@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

The backport to 3.4 failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-3.4 3.4
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-3.4
# Create a new branch
git switch --create backport/backport-20204-to-3.4
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 947efd33b930c570055eaf5ace272fe092b2bb5f
# Push it to GitHub
git push --set-upstream origin backport/backport-20204-to-3.4
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-3.4

Then, create a pull request where the base branch is 3.4 and the compare/head branch is backport/backport-20204-to-3.4.

@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

The backport to 3.4 failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-3.4 3.4
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-3.4
# Create a new branch
git switch --create backport/backport-20204-to-3.4
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 947efd33b930c570055eaf5ace272fe092b2bb5f
# Push it to GitHub
git push --set-upstream origin backport/backport-20204-to-3.4
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-3.4

Then, create a pull request where the base branch is 3.4 and the compare/head branch is backport/backport-20204-to-3.4.

1 similar comment
@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

The backport to 3.4 failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-3.4 3.4
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-3.4
# Create a new branch
git switch --create backport/backport-20204-to-3.4
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 947efd33b930c570055eaf5ace272fe092b2bb5f
# Push it to GitHub
git push --set-upstream origin backport/backport-20204-to-3.4
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-3.4

Then, create a pull request where the base branch is 3.4 and the compare/head branch is backport/backport-20204-to-3.4.

sandeshkr419 added a commit to sandeshkr419/OpenSearch that referenced this pull request Dec 12, 2025
Co-authored-by: Sandesh Kumar <sandeshkr419@gmail.com>
prudhvigodithi pushed a commit that referenced this pull request Dec 12, 2025
Co-authored-by: Anthony Leong <aj.leong623@gmail.com>
fdesu pushed a commit to fdesu/OpenSearch that referenced this pull request Dec 13, 2025
Co-authored-by: Sandesh Kumar <sandeshkr419@gmail.com>
liuguoqingfz pushed a commit to liuguoqingfz/OpenSearch that referenced this pull request Dec 15, 2025
Co-authored-by: Sandesh Kumar <sandeshkr419@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 3.4 Backport to 3.4 branch backport-failed bug Something isn't working Search:Aggregations skip-changelog v3.4.0 Issues and PRs related to version 3.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] array_index_out_of_bounds_exception on aggregations with unsigned_long

4 participants