Skip to content

Conversation

@BeomSeogKim
Copy link
Contributor

Description

[Describe what this change achieves]
As proposed in issue #17874, this PR refactors several if-else chains that use instanceof checks into more readable and modern Java 17 pattern matching switch statements. This improves code clarity and maintainability.

Affected files:
  - Numbers.java: toLongExact, toBigIntegerExact methods
  - ExceptionsHelper.java: exception handling methods
  - NestedHelper.java: query matching methods
  - ValueSource.java: value wrapping logic
  - SearchSortValuesAndFormats.java: sort value formatting
  - BulkItemResponse.java: response type serialization
  - DocWriteRequest.java: request serialization methods

Related Issues

Resolves #17874

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.

Copilot AI review requested due to automatic review settings August 7, 2025 15:03
@github-actions github-actions bot added enhancement Enhancement or improvement to existing feature or request good first issue Good for newcomers labels Aug 7, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors if-else chains that use instanceof checks into modern Java 17 pattern matching switch expressions, improving code readability and maintainability.

  • Converts traditional instanceof checks with explicit casting to pattern matching syntax
  • Replaces long if-else chains with more concise and readable switch expressions
  • Modernizes exception handling patterns using switch expressions

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
SearchSortValuesAndFormats.java Converts sort value type checking from if-else chain to switch expression
ValueSource.java Refactors value wrapping logic to use pattern matching switch
NestedHelper.java Modernizes query type checking methods with switch expressions
BulkItemResponse.java Simplifies response type serialization using switch
DocWriteRequest.java Converts document request serialization to switch pattern
SocketChannelContext.java Updates exception handling to use switch expression
NioSelectorGroup.java Modernizes exception type checking with pattern matching
LoggerMessageFormat.java Converts array type checking to switch expression
BytesReference.java Simplifies stream type checking with switch
ExceptionsHelper.java Refactors exception handling methods to use switch expressions
Numbers.java Converts number type checking methods to pattern matching switch

@BeomSeogKim BeomSeogKim closed this Aug 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2025

❌ Gradle check result for 59c35f7: 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?

@BeomSeogKim
Copy link
Contributor Author

Hello maintainers,

I am reopening this pull request. I had briefly closed it because I was surprised by the automated comment from the bot and wasn't sure what the next step was. 😅

I've reopened it now to proceed. If there's a specific action required from me based on the bot's message, could you please guide me?

Thank you for your understanding.

@BeomSeogKim BeomSeogKim reopened this Aug 7, 2025
@cwperks
Copy link
Member

cwperks commented Aug 7, 2025

I've never seen that before. Did Copilot just perform a review unprompted?

@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2025

❌ Gradle check result for f384f62: 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: BeomSeogKim <[email protected]>
@BeomSeogKim BeomSeogKim force-pushed the feature/refactor-switch-17484 branch from f384f62 to 55675d6 Compare August 9, 2025 12:27
@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2025

❌ Gradle check result for 55675d6: 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?

@opensearch-trigger-bot
Copy link
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot bot added the stalled Issues that have stalled label Sep 8, 2025
@BeomSeogKim BeomSeogKim force-pushed the feature/refactor-switch-17484 branch from 58f7968 to 1fe001d Compare September 9, 2025 13:23
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

✅ Gradle check result for 1fe001d: SUCCESS

@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 75.38462% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.89%. Comparing base (3e747cb) to head (50931d6).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
...in/java/org/opensearch/action/DocWriteRequest.java 57.14% 10 Missing and 2 partials ⚠️
...earch/core/common/logging/LoggerMessageFormat.java 0.00% 10 Missing ⚠️
...java/org/opensearch/index/search/NestedHelper.java 85.71% 1 Missing and 6 partials ⚠️
.../opensearch/search/SearchSortValuesAndFormats.java 58.33% 4 Missing and 1 partial ⚠️
.../java/org/opensearch/nio/SocketChannelContext.java 0.00% 4 Missing ⚠️
...c/main/java/org/opensearch/ingest/ValueSource.java 84.00% 2 Missing and 2 partials ⚠️
...main/java/org/opensearch/nio/NioSelectorGroup.java 0.00% 3 Missing ⚠️
...a/org/opensearch/action/bulk/BulkItemResponse.java 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #18965      +/-   ##
============================================
+ Coverage     72.79%   72.89%   +0.10%     
- Complexity    69605    69630      +25     
============================================
  Files          5658     5658              
  Lines        320079   320061      -18     
  Branches      46345    46290      -55     
============================================
+ Hits         232996   233307     +311     
+ Misses        68230    67866     -364     
- Partials      18853    18888      +35     

☔ 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.

@BeomSeogKim
Copy link
Contributor Author

@andrross could you check one more time? I refactor the code causing test failure.

@opensearch-trigger-bot opensearch-trigger-bot bot removed the stalled Issues that have stalled label Sep 9, 2025
Copy link
Member

@sandeshkr419 sandeshkr419 left a comment

Choose a reason for hiding this comment

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

The changes look neat with a small nit-pick.

Thanks for working on these changes.

@github-actions
Copy link
Contributor

✅ Gradle check result for 50931d6: SUCCESS

@andrross andrross merged commit d5b4817 into opensearch-project:main Sep 12, 2025
31 checks passed
jainankitk pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 22, 2025
jainankitk pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 22, 2025
jainankitk pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 22, 2025
asimmahmood1 pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 23, 2025
pranikum pushed a commit to pranikum/OpenSearch that referenced this pull request Sep 23, 2025
vinaykpud pushed a commit to vinaykpud/OpenSearch that referenced this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement or improvement to existing feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Make use of Java 17 pattern matching switch statements where possible

4 participants