@@ -272,11 +272,9 @@ public static void readMultiLineFormat(
272272 )
273273 ) {
274274 Map <String , Object > source = parser .map ();
275- // In Jackson 2.21+, parser.map() leaves the parser at END_OBJECT, need to advance past it
276- XContentParser .Token token = parser .currentToken () == XContentParser .Token .END_OBJECT
277- ? parser .nextToken ()
278- : parser .currentToken ();
279- if (token != null ) {
275+ // In Jackson 2.21+, parser.map() may leave the parser past END_OBJECT
276+ // Only check for extra tokens if we're still positioned in the stream
277+ if (parser .currentToken () != null && parser .nextToken () != null ) {
280278 throw new XContentParseException (parser .getTokenLocation (), "Unexpected token after end of object" );
281279 }
282280 Object expandWildcards = null ;
@@ -364,11 +362,9 @@ public static void readMultiLineFormat(
364362 )
365363 ) {
366364 consumer .accept (searchRequest , parser );
367- // In Jackson 2.21+, after parsing, the parser may be at END_OBJECT, need to advance past it
368- XContentParser .Token token = parser .currentToken () == XContentParser .Token .END_OBJECT
369- ? parser .nextToken ()
370- : parser .currentToken ();
371- if (token != null ) {
365+ // In Jackson 2.21+, after parsing, the parser may be past END_OBJECT
366+ // Only check for extra tokens if we're still positioned in the stream
367+ if (parser .currentToken () != null && parser .nextToken () != null ) {
372368 throw new XContentParseException (parser .getTokenLocation (), "Unexpected token after end of object" );
373369 }
374370 }
0 commit comments