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
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 ;
@@ -545,8 +544,9 @@ protected String contentType() {
545
544
@ Override
546
545
protected void parseCreateField (DocumentParserContext context ) throws IOException {
547
546
InetAddress address ;
547
+ String value = context .parser ().textOrNull ();
548
548
try {
549
- address = value ( context . parser (), nullValue );
549
+ address = value == null ? nullValue : InetAddresses . forString ( value );
550
550
} catch (IllegalArgumentException e ) {
551
551
if (ignoreMalformed ) {
552
552
context .addIgnoredField (fieldType ().name ());
@@ -564,14 +564,6 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
564
564
}
565
565
}
566
566
567
- private static InetAddress value (XContentParser parser , InetAddress nullValue ) throws IOException {
568
- String value = parser .textOrNull ();
569
- if (value == null ) {
570
- return nullValue ;
571
- }
572
- return InetAddresses .forString (value );
573
- }
574
-
575
567
private void indexValue (DocumentParserContext context , InetAddress address ) {
576
568
if (dimension ) {
577
569
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