Skip to content

Conversation

@ajleong623
Copy link
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.

@coderabbitai
Copy link

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
Contributor

github-actions bot commented Dec 9, 2025

✅ Gradle check result for 5eb3203: SUCCESS

@codecov
Copy link

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
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 <[email protected]>
Signed-off-by: Anthony Leong <[email protected]>
@github-actions
Copy link
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 <[email protected]>
@github-actions
Copy link
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
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 <[email protected]>
@github-actions
Copy link
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 <[email protected]>
ajleong623 and others added 2 commits December 11, 2025 12:04
Signed-off-by: Anthony Leong <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
release-notes/opensearch.release-notes-3.4.0.md (1)

11-11: Apply hyphenation to compound adjectives.

Lines 11 and 13 contain compound adjectives that should be hyphenated when modifying nouns: "context aware" → "context-aware", "Server side" → "server-side", "client side" → "client-side".

Apply these diffs:

- Add a mapper for context aware segments grouping criteria ([#19233](https://github.com/opensearch-project/OpenSearch/pull/19233))
+ Add a mapper for context-aware segments grouping criteria ([#19233](https://github.com/opensearch-project/OpenSearch/pull/19233))
- Add support for repository with Server side encryption enabled and client side encryption as well based on a flag ([#19630](https://github.com/opensearch-project/OpenSearch/pull/19630))
+ Add support for repository with server-side encryption enabled and client-side encryption as well based on a flag ([#19630](https://github.com/opensearch-project/OpenSearch/pull/19630))

Also applies to: 13-13

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9fed63d and f569f91.

📒 Files selected for processing (1)
  • release-notes/opensearch.release-notes-3.4.0.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
release-notes/opensearch.release-notes-3.4.0.md

[uncategorized] ~11-~11: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...nSearch/pull/19539)) - Add a mapper for context aware segments grouping criteria ([#19233](ht...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~13-~13: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...568)) - Add support for repository with Server side encryption enabled and client side encr...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~13-~13: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...with Server side encryption enabled and client side encryption as well based on a flag ([#1...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: assemble (21, macos-15)
  • GitHub Check: assemble (21, ubuntu-24.04-arm)
  • GitHub Check: assemble (25, ubuntu-24.04-arm)
  • GitHub Check: assemble (21, ubuntu-latest)
  • GitHub Check: assemble (21, windows-latest)
  • GitHub Check: assemble (25, ubuntu-latest)
  • GitHub Check: verify-changelog
  • GitHub Check: precommit (25, macos-15)
  • GitHub Check: precommit (25, ubuntu-24.04-arm)
  • GitHub Check: precommit (21, ubuntu-24.04-arm)
  • GitHub Check: precommit (25, windows-latest)
  • GitHub Check: precommit (25, macos-15-intel)
  • GitHub Check: precommit (21, windows-latest)
  • GitHub Check: Analyze (java)
  • GitHub Check: precommit (21, macos-15-intel)
  • GitHub Check: detect-breaking-change
  • GitHub Check: precommit (21, macos-15)
  • GitHub Check: precommit (21, windows-2025, true)
🔇 Additional comments (1)
release-notes/opensearch.release-notes-3.4.0.md (1)

105-105: New release notes entry correctly documents the fix.

The addition of the new entry "Fix array out of bounds during aggregation" at line 105 appropriately captures the bug fix from PR #20204 and is well-placed within the Fixed section.

Signed-off-by: Sandesh Kumar <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
release-notes/opensearch.release-notes-3.4.0.md (2)

9-9: Typo corrected: "unsigned_long" spelling fixed.

The typo "usigned_long" has been corrected to "unsigned_long", aligning with the correct field type name referenced in the PR.


88-88: Formatting corrected: space added before PR reference.

The spacing has been standardized to match other entries in the release notes.

🧹 Nitpick comments (1)
release-notes/opensearch.release-notes-3.4.0.md (1)

11-11: Add hyphens to compound adjectives per style guidelines.

Per static analysis, compound adjectives modifying nouns should use hyphens for clarity:

  • Line 11: "context aware segments" → "context-aware segments"
  • Line 13: "Server side encryption" → "Server-side encryption" (two instances)

Apply this diff:

- Add a mapper for context aware segments grouping criteria ([#19233](https://github.com/opensearch-project/OpenSearch/pull/19233))
+ Add a mapper for context-aware segments grouping criteria ([#19233](https://github.com/opensearch-project/OpenSearch/pull/19233))
- Add support for repository with Server side encryption enabled and client side encryption as well based on a flag ([#19630](https://github.com/opensearch-project/OpenSearch/pull/19630))
+ Add support for repository with Server-side encryption enabled and client-side encryption as well based on a flag ([#19630](https://github.com/opensearch-project/OpenSearch/pull/19630))

Also applies to: 13-13

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f569f91 and d90d6a9.

📒 Files selected for processing (1)
  • release-notes/opensearch.release-notes-3.4.0.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
release-notes/opensearch.release-notes-3.4.0.md

[uncategorized] ~11-~11: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...nSearch/pull/19539)) - Add a mapper for context aware segments grouping criteria ([#19233](ht...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~13-~13: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...568)) - Add support for repository with Server side encryption enabled and client side encr...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~13-~13: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...with Server side encryption enabled and client side encryption as well based on a flag ([#1...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

🔇 Additional comments (1)
release-notes/opensearch.release-notes-3.4.0.md (1)

105-105: New entry for array out of bounds fix added appropriately.

Line 105 correctly documents the fix for the array out of bounds exception during aggregations, referencing PR #20204. The formatting aligns with other entries, and the placement in the "Fixed" section is appropriate.

@github-actions
Copy link
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?

@asimmahmood1
Copy link
Contributor

LGTM! Good find @ajleong623.

Since this was introduced in 3.0, so just porting to 3.4 is good enough: #14464

@asimmahmood1
Copy link
Contributor

Flaky test failure:

> Task :distribution:bwc:bugfix:buildBwcLinuxTar
 [3.3.2] 
Exception in thread "main" java.io.IOException: Downloading from https://services.gradle.org/distributions/gradle-8.14.3-all.zip failed: timeout (10000ms)
 [3.3.2] 	at org.gradle.wrapper.Install.forceFetch(SourceFile:4)
 [3.3.2] 	at org.gradle.wrapper.Install$1.call(SourceFile:8)
 [3.3.2] 	at org.gradle.wrapper.GradleWrapperMain.main(SourceFile:67)
 [3.3.2] Caused by: java.net.SocketTimeoutException: Read timed out
 [3.3.2] 	at java.****/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:278)
 [3.3.2] 	at java.****/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:304)
 [3.3.2] 	at java.****/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:346)
 [3.3.2] 	at java.****/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:796)
 [3.3.2] 	at java.****/java.net.Socket$SocketInputStream.read(Socket.java:1099)
 [3.3.2] 	at java.****/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:489)
 [3.3.2] 	at java.****/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:483)
 [3.3.2] 	at java.****/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
 [3.3.2] 	at java.****/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1461)
 [3.3.2] 	at java.****/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1066)
 [3.3.2] 	at java.****/java.io.BufferedInputStream.fill(BufferedInputStream.java:291)
 [3.3.2] 	at java.****/java.io.BufferedInputStream.read1(BufferedInputStream.java:347)
 [3.3.2] 	at java.****/java.io.BufferedInputStream.implRead(BufferedInputStream.java:420)
 [3.3.2] 	at java.****/java.io.BufferedInputStream.read(BufferedInputStream.java:399)
 [3.3.2] 	at java.****/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:827)
 [3.3.2] 	at java.****/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:759)
 [3.3.2] 	at java.****/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1706)
 [3.3.2] 	at java.****/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1615)
 [3.3.2] 	at java.****/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223)
 [3.3.2] 	at org.gradle.wrapper.Install.forceFetch(SourceFile:2)
 [3.3.2] 	... 2 more
Output for /var/jenkins/workspace/gradle-check/search/distribution/bwc/bugfix/build/bwc/checkout-3.3/gradlew:

> Task :plugins:workload-management:javaRestTest
WARNING: Using incubator modules: jdk.incubator.vector
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction
WARNING: Please consider reporting this to the maintainers of class net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release

> Task :distribution:bwc:bugfix:buildBwcLinuxTar FAILED
> Task :test:framework:missingJavadoc
> Task :qa:smoke-test-multinode:forbiddenApisResources
> Task :plugins:transport-reactor-netty4:generateNotice
> Task :qa:wildfly:spotlessMisc

@github-actions
Copy link
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
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
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
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
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
prudhvigodithi pushed a commit that referenced this pull request Dec 12, 2025
fdesu pushed a commit to fdesu/OpenSearch that referenced this pull request Dec 13, 2025
liuguoqingfz pushed a commit to liuguoqingfz/OpenSearch that referenced this pull request Dec 15, 2025
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