File tree Expand file tree Collapse file tree 5 files changed +10
-13
lines changed
libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json
main/java/org/elasticsearch/index/mapper
test/java/org/elasticsearch Expand file tree Collapse file tree 5 files changed +10
-13
lines changed Original file line number Diff line number Diff line change
1
+ pr : 112703
2
+ summary : JSON parse failures should be 4xx codes
3
+ area : Infra/Core
4
+ type : bug
5
+ issues : []
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ public String text() throws IOException {
111
111
}
112
112
113
113
private void throwOnNoText () {
114
- throw new IllegalStateException ( "Can't get text on a " + currentToken () + " at " + getTokenLocation ());
114
+ throw new IllegalArgumentException ( "Expected text at " + getTokenLocation () + " but found " + currentToken ());
115
115
}
116
116
117
117
@ Override
Original file line number Diff line number Diff line change 42
42
import org .elasticsearch .search .aggregations .support .CoreValuesSourceType ;
43
43
import org .elasticsearch .search .lookup .FieldValues ;
44
44
import org .elasticsearch .search .lookup .SearchLookup ;
45
- import org .elasticsearch .xcontent .XContentParser ;
46
45
47
46
import java .io .IOException ;
48
47
import java .net .InetAddress ;
@@ -533,8 +532,9 @@ protected String contentType() {
533
532
@ Override
534
533
protected void parseCreateField (DocumentParserContext context ) throws IOException {
535
534
InetAddress address ;
535
+ String value = context .parser ().textOrNull ();
536
536
try {
537
- address = value ( context . parser (), nullValue );
537
+ address = value == null ? nullValue : InetAddresses . forString ( value );
538
538
} catch (IllegalArgumentException e ) {
539
539
if (ignoreMalformed ) {
540
540
context .addIgnoredField (fieldType ().name ());
@@ -552,14 +552,6 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
552
552
}
553
553
}
554
554
555
- private static InetAddress value (XContentParser parser , InetAddress nullValue ) throws IOException {
556
- String value = parser .textOrNull ();
557
- if (value == null ) {
558
- return nullValue ;
559
- }
560
- return InetAddresses .forString (value );
561
- }
562
-
563
555
private void indexValue (DocumentParserContext context , InetAddress address ) {
564
556
if (dimension ) {
565
557
context .getDimensions ().addIp (fieldType ().name (), address ).validate (context .indexSettings ());
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ public void testResourceValidation() throws Exception {
66
66
builder .startObject ("UNEXPECTED" ).endObject ().endObject ();
67
67
68
68
try (var stream = BytesReference .bytes (builder ).streamInput ()) {
69
- expectThrows (IllegalStateException .class , () -> ReferenceDocs .readLinksBySymbol (stream ));
69
+ expectThrows (IllegalArgumentException .class , () -> ReferenceDocs .readLinksBySymbol (stream ));
70
70
}
71
71
}
72
72
Original file line number Diff line number Diff line change @@ -373,7 +373,7 @@ public void testParseFailsWithTermsArray() {
373
373
"message1" : ["term1", "term2"]
374
374
}
375
375
}""" ;
376
- expectThrows (IllegalStateException .class , () -> parseQuery (json2 ));
376
+ expectThrows (IllegalArgumentException .class , () -> parseQuery (json2 ));
377
377
}
378
378
379
379
public void testExceptionUsingAnalyzerOnNumericField () {
You can’t perform that action at this time.
0 commit comments