@@ -164,38 +164,14 @@ public void parse(
164
164
continue ;
165
165
}
166
166
if (token != XContentParser .Token .START_OBJECT ) {
167
- throw new IllegalArgumentException (
168
- "Malformed action/metadata line ["
169
- + line
170
- + "], expected "
171
- + XContentParser .Token .START_OBJECT
172
- + " but found ["
173
- + token
174
- + "]"
175
- );
167
+ throwOnMalformedStart (line , token );
176
168
}
177
169
// Move to FIELD_NAME, that's the action
178
- token = parser .nextToken ();
179
- if (token != XContentParser .Token .FIELD_NAME ) {
180
- throw new IllegalArgumentException (
181
- "Malformed action/metadata line ["
182
- + line
183
- + "], expected "
184
- + XContentParser .Token .FIELD_NAME
185
- + " but found ["
186
- + token
187
- + "]"
188
- );
189
- }
190
- String action = parser .currentName ();
191
- if (SUPPORTED_ACTIONS .contains (action ) == false ) {
192
- throw new IllegalArgumentException (
193
- "Malformed action/metadata line ["
194
- + line
195
- + "], expected field [create], [delete], [index] or [update] but found ["
196
- + action
197
- + "]"
198
- );
170
+ String action = parser .nextFieldName ();
171
+ if (action == null ) {
172
+ throwOnMalformedLine (line , parser );
173
+ } else if (SUPPORTED_ACTIONS .contains (action ) == false ) {
174
+ throwOnUnsupportedAction (line , action );
199
175
}
200
176
201
177
String index = defaultIndex ;
@@ -444,6 +420,34 @@ public void parse(
444
420
}
445
421
}
446
422
423
+ private static void throwOnMalformedStart (int line , XContentParser .Token token ) {
424
+ throw new IllegalArgumentException (
425
+ "Malformed action/metadata line [" + line + "], expected " + XContentParser .Token .START_OBJECT + " but found [" + token + "]"
426
+ );
427
+ }
428
+
429
+ private static void throwOnMalformedLine (int line , XContentParser parser ) {
430
+ throw new IllegalArgumentException (
431
+ "Malformed action/metadata line ["
432
+ + line
433
+ + "], expected "
434
+ + XContentParser .Token .FIELD_NAME
435
+ + " but found ["
436
+ + parser .currentToken ()
437
+ + "]"
438
+ );
439
+ }
440
+
441
+ private static void throwOnUnsupportedAction (int line , String action ) {
442
+ throw new IllegalArgumentException (
443
+ "Malformed action/metadata line ["
444
+ + line
445
+ + "], expected field [create], [delete], [index] or [update] but found ["
446
+ + action
447
+ + "]"
448
+ );
449
+ }
450
+
447
451
@ UpdateForV9
448
452
// Warnings will need to be replaced with XContentEOFException from 9.x
449
453
private static void warnBulkActionNotProperlyClosed (String message ) {
0 commit comments