Fix ClassCastException on malformed mappings in create index#22371
Fix ClassCastException on malformed mappings in create index#22371vishdivs wants to merge 3 commits into
Conversation
Signed-off-by: Divyansh Sharma <vishdivs@amazon.com>
PR Reviewer Guide 🔍(Review updated until commit 7c1adf9)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 7c1adf9 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 9a5ed34
Suggestions up to commit 4a61a97
Suggestions up to commit 8ce022f
|
Signed-off-by: Divyansh Sharma <vishdivs@amazon.com>
|
Persistent review updated to latest commit 4a61a97 |
|
Persistent review updated to latest commit 9a5ed34 |
|
❌ Gradle check result for 9a5ed34: 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: Divyansh Sharma <vishdivs@amazon.com>
|
Persistent review updated to latest commit 7c1adf9 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22371 +/- ##
============================================
- Coverage 73.40% 73.32% -0.08%
+ Complexity 76106 76046 -60
============================================
Files 6076 6076
Lines 345523 345527 +4
Branches 49737 49739 +2
============================================
- Hits 253627 253358 -269
- Misses 71686 71942 +256
- Partials 20210 20227 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Added type validation for the
mappingsfield inCreateIndexRequest#source(). Previously, passing a non-object value (e.g., a string like"{}") for themappingskey resulted in a 500 Internal ServerError with a
ClassCastException. This change adds explicit type checks that return a proper 400 Bad Request with a clear error message.Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
Testing
Before (500 ClassCastException):
curl -X PUT "localhost:9200/vishdivs_doc"
-H "Content-Type: application/json"
-d '{
"mappings": "{}"
}'
{"error":{"root_cause":[{"type":"class_cast_exception","reason":"class java.lang.String cannot be cast to class java.util.Map (java.lang.String and java.util.Map are in module java.base of loader
'bootstrap')"}],"type":"class_cast_exception","reason":"class java.lang.String cannot be cast to class java.util.Map (java.lang.String and java.util.Map are in module java.base of loader
'bootstrap')"},"status":500}
After (400 with clear error message):
curl -X PUT "localhost:9200/vishdivs_doc"
-H "Content-Type: application/json"
-d '{
"mappings": "{}"
}'
{"error":{"root_cause":[{"type":"parse_exception","reason":"key [mapping] must be an object"}],"type":"parse_exception","reason":"key [mapping] must be an object"},"status":400}
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.