Make use of Java 17 pattern matching switch statements#17909
Make use of Java 17 pattern matching switch statements#17909JaySabva wants to merge 6 commits intoopensearch-project:mainfrom
Conversation
|
❌ Gradle check result for 38eeb9d: 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? |
|
❕ Gradle check result for f3e2454: UNSTABLE Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17909 +/- ##
=========================================
Coverage 72.43% 72.44%
- Complexity 66789 66809 +20
=========================================
Files 5449 5452 +3
Lines 309085 309181 +96
Branches 44979 44963 -16
=========================================
+ Hits 223899 223998 +99
+ Misses 66906 66843 -63
- Partials 18280 18340 +60 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
❌ Gradle check result for f2ae0fa: 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? |
There was a problem hiding this comment.
Thanks for raising a PR @JaySabva! There are other classes as well. For ex:
- https://github.com/opensearch-project/OpenSearch/blob/main/plugins/repository-s3/src/internalClusterTest/java/org/opensearch/repositories/s3/S3BlobStoreRepositoryTests.java#L357-L368
- https://github.com/opensearch-project/OpenSearch/blob/main/buildSrc/src/main/java/org/opensearch/gradle/util/Util.java#L135-L145
To name a few.
Also, DCO check is failing. Can you sign your commit withgit commit -s --amendand push again? To sign the commits you need to include-sflag
| return true; | ||
| } | ||
| case OpenSearchToParentBlockJoinQuery ostpbjq -> ostpbjq.getPath() != null; | ||
| case null -> true; |
There was a problem hiding this comment.
Wouldn't this map to default case?
There was a problem hiding this comment.
I think that will raise null pointer exception I tried that in my scratch file.
There was a problem hiding this comment.
In this and the other cases with case null, I believe you can collapse them both into a single branch, like:
case null, default -> true
| } else { | ||
| return true; | ||
| } | ||
| case null -> true; |
|
I thought only instance of if else. Sure I will make changes. |
…witch statements Signed-off-by: Jay Sabva <202101224@daiict.ac.in>
…witch statements Signed-off-by: Jay Sabva <202101224@daiict.ac.in>
…witch statements Signed-off-by: Jay Sabva <202101224@daiict.ac.in>
…witch statements Signed-off-by: Jay Sabva <202101224@daiict.ac.in>
…witch statements Signed-off-by: Jay Sabva <202101224@daiict.ac.in>
…witch statements Signed-off-by: Jay Sabva <202101224@daiict.ac.in>
|
❌ Gradle check result for 5f4340f: 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? |
| return switch (t) { | ||
| case OpenSearchException ose -> ose.status(); | ||
| case IllegalArgumentException iae -> RestStatus.BAD_REQUEST; | ||
| case JsonParseException jpe -> RestStatus.BAD_REQUEST; | ||
| case OpenSearchRejectedExecutionException osre -> RestStatus.TOO_MANY_REQUESTS; | ||
| case NotXContentException nxce -> RestStatus.BAD_REQUEST; | ||
| case null -> RestStatus.INTERNAL_SERVER_ERROR; | ||
| default -> RestStatus.INTERNAL_SERVER_ERROR; | ||
| }; |
There was a problem hiding this comment.
| return switch (t) { | |
| case OpenSearchException ose -> ose.status(); | |
| case IllegalArgumentException iae -> RestStatus.BAD_REQUEST; | |
| case JsonParseException jpe -> RestStatus.BAD_REQUEST; | |
| case OpenSearchRejectedExecutionException osre -> RestStatus.TOO_MANY_REQUESTS; | |
| case NotXContentException nxce -> RestStatus.BAD_REQUEST; | |
| case null -> RestStatus.INTERNAL_SERVER_ERROR; | |
| default -> RestStatus.INTERNAL_SERVER_ERROR; | |
| }; | |
| return switch (t) { | |
| case OpenSearchException ose -> ose.status(); | |
| case IllegalArgumentException || JsonParseException || NotXContentException -> RestStatus.BAD_REQUEST; | |
| case OpenSearchRejectedExecutionException -> RestStatus.TOO_MANY_REQUESTS; | |
| case null, Throwable _ -> RestStatus.INTERNAL_SERVER_ERROR; | |
| }; |
|
This PR is stalled because it has been open for 30 days with no activity. |
Description
Changed if-else instaceof check to JAVA 17 pattern matching switch
Related Issues
Resolves #17874
Check List
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.