File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed 
libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json 
qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http 
server/src/test/java/org/elasticsearch/common/xcontent/json Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1+ pr : 114445 
2+ summary : Wrap jackson exception on malformed json string 
3+ area : Infra/Core 
4+ type : bug 
5+ issues :
6+  - 114142 
Original file line number Diff line number Diff line change @@ -108,7 +108,11 @@ public String text() throws IOException {
108108        if  (currentToken ().isValue () == false ) {
109109            throwOnNoText ();
110110        }
111-         return  parser .getText ();
111+         try  {
112+             return  parser .getText ();
113+         } catch  (JsonParseException  e ) {
114+             throw  newXContentParseException (e );
115+         }
112116    }
113117
114118    private  void  throwOnNoText () {
Original file line number Diff line number Diff line change @@ -74,8 +74,7 @@ public void testBulkInvalidIndexNameString() throws IOException {
7474
7575        ResponseException  responseException  = expectThrows (ResponseException .class , () -> getRestClient ().performRequest (request ));
7676        assertThat (responseException .getResponse ().getStatusLine ().getStatusCode (), equalTo (BAD_REQUEST .getStatus ()));
77-         assertThat (responseException .getMessage (), containsString ("could not parse bulk request body" ));
78-         assertThat (responseException .getMessage (), containsString ("json_parse_exception" ));
77+         assertThat (responseException .getMessage (), containsString ("x_content_parse_exception" ));
7978        assertThat (responseException .getMessage (), containsString ("Invalid UTF-8" ));
8079    }
8180
Original file line number Diff line number Diff line change 1111
1212import  org .elasticsearch .common .xcontent .BaseXContentTestCase ;
1313import  org .elasticsearch .xcontent .XContentGenerator ;
14+ import  org .elasticsearch .xcontent .XContentParseException ;
15+ import  org .elasticsearch .xcontent .XContentParser ;
16+ import  org .elasticsearch .xcontent .XContentParserConfiguration ;
1417import  org .elasticsearch .xcontent .XContentType ;
1518import  org .elasticsearch .xcontent .json .JsonXContent ;
1619
@@ -28,4 +31,14 @@ public void testBigInteger() throws Exception {
2831        XContentGenerator  generator  = JsonXContent .jsonXContent .createGenerator (os );
2932        doTestBigInteger (generator , os );
3033    }
34+ 
35+     public  void  testMalformedJsonFieldThrowsXContentException () throws  Exception  {
36+         String  json  = "{\" test\" :\" /*/}" ;
37+         try  (XContentParser  parser  = JsonXContent .jsonXContent .createParser (XContentParserConfiguration .EMPTY , json )) {
38+             parser .nextToken ();
39+             parser .nextToken ();
40+             parser .nextToken ();
41+             assertThrows (XContentParseException .class , () -> parser .text ());
42+         }
43+     }
3144}
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments