Skip to content

Commit

Permalink
Merge pull request #10307 from obourgain/fix_parsing_multipercolate
Browse files Browse the repository at this point in the history
Fix wrong use of currentFieldName outside of a parsing loop.

Close #10307
  • Loading branch information
jpountz committed Mar 30, 2015
2 parents 38ec508 + 7a5e3c1 commit 80fe8d1
Showing 1 changed file with 24 additions and 19 deletions.
Expand Up @@ -175,19 +175,7 @@ public List<? extends IndicesRequest> subRequests() {
private void parsePercolateAction(XContentParser parser, PercolateRequest percolateRequest, boolean allowExplicitIndex) throws IOException {
String globalIndex = indices != null && indices.length > 0 ? indices[0] : null;

Map<String, Object> header = new HashMap<>();

String currentFieldName = null;
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
header.put(currentFieldName, parser.text());
} else if (token == XContentParser.Token.START_ARRAY) {
header.put(currentFieldName, parseArray(parser));
}
}
Map<String, Object> header = parseToMap(parser);

IndicesOptions defaultOptions = indicesOptions;
boolean ignoreUnavailable = defaultOptions.ignoreUnavailable();
Expand Down Expand Up @@ -226,11 +214,11 @@ private void parsePercolateAction(XContentParser parser, PercolateRequest percol
percolateRequest.preference((String) value);
} else if ("percolate_routing".equals(entry.getKey()) || "percolateRouting".equals(entry.getKey())) {
percolateRequest.routing((String) value);
} else if ("ignore_unavailable".equals(currentFieldName) || "ignoreUnavailable".equals(currentFieldName)) {
} else if ("ignore_unavailable".equals(entry.getKey()) || "ignoreUnavailable".equals(entry.getKey())) {
ignoreUnavailable = Boolean.valueOf((String) value);
} else if ("allow_no_indices".equals(currentFieldName) || "allowNoIndices".equals(currentFieldName)) {
} else if ("allow_no_indices".equals(entry.getKey()) || "allowNoIndices".equals(entry.getKey())) {
allowNoIndices = Boolean.valueOf((String) value);
} else if ("expand_wildcards".equals(currentFieldName) || "expandWildcards".equals(currentFieldName)) {
} else if ("expand_wildcards".equals(entry.getKey()) || "expandWildcards".equals(entry.getKey())) {
String[] wildcards;
if (value instanceof String[]) {
wildcards = (String[]) value;
Expand Down Expand Up @@ -281,11 +269,11 @@ private void parsePercolateAction(XContentParser parser, PercolateRequest percol
percolateRequest.preference((String) value);
} else if ("routing".equals(entry.getKey())) {
percolateRequest.routing((String) value);
} else if ("ignore_unavailable".equals(currentFieldName) || "ignoreUnavailable".equals(currentFieldName)) {
} else if ("ignore_unavailable".equals(entry.getKey()) || "ignoreUnavailable".equals(entry.getKey())) {
ignoreUnavailable = Boolean.valueOf((String) value);
} else if ("allow_no_indices".equals(currentFieldName) || "allowNoIndices".equals(currentFieldName)) {
} else if ("allow_no_indices".equals(entry.getKey()) || "allowNoIndices".equals(entry.getKey())) {
allowNoIndices = Boolean.valueOf((String) value);
} else if ("expand_wildcards".equals(currentFieldName) || "expandWildcards".equals(currentFieldName)) {
} else if ("expand_wildcards".equals(entry.getKey()) || "expandWildcards".equals(entry.getKey())) {
String[] wildcards;
if (value instanceof String[]) {
wildcards = (String[]) value;
Expand All @@ -308,6 +296,23 @@ private void parsePercolateAction(XContentParser parser, PercolateRequest percol
percolateRequest.indicesOptions(IndicesOptions.fromOptions(ignoreUnavailable, allowNoIndices, expandWildcardsOpen, expandWildcardsClosed, defaultOptions));
}

private Map<String, Object> parseToMap(XContentParser parser) throws IOException {
Map<String, Object> header = new HashMap<>();

String currentFieldName = null;
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
header.put(currentFieldName, parser.text());
} else if (token == XContentParser.Token.START_ARRAY) {
header.put(currentFieldName, parseArray(parser));
}
}
return header;
}

private String[] parseArray(XContentParser parser) throws IOException {
final List<String> list = new ArrayList<>();
assert parser.currentToken() == XContentParser.Token.START_ARRAY;
Expand Down

0 comments on commit 80fe8d1

Please sign in to comment.