Skip to content

Commit

Permalink
REST Get Field Mapping API: Fix NPE if field not existent
Browse files Browse the repository at this point in the history
When fixing #4738, a small issue leaked into the implementation.
The equals check in the RestAction only applied when the master node
returned the rest request, otherwise the object equality would not hold
due to being transferred over the wire and being deserialized into
another object (from and an equality point of view) than the
FieldMappingMetaData.NULL object - this could result in serialization
exceptions as an empty length bytes reference is used in toXContent.
  • Loading branch information
spinscale committed Jan 30, 2014
1 parent 33f563f commit dce39b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Expand Up @@ -108,6 +108,10 @@ public Map<String, Object> sourceAsMap() {
return XContentHelper.convertToMap(source.array(), source.arrayOffset(), source.length(), true).v2();
}

public boolean isNull() {
return NULL.fullName().equals(fullName) && NULL.source.length() == source.length();
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("full_name", fullName);
Expand Down
Expand Up @@ -119,7 +119,7 @@ private boolean isFieldMappingMissingField(ImmutableMap<String, ImmutableMap<Str
for (ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>> value : mappingsByIndex.values()) {
for (ImmutableMap<String, FieldMappingMetaData> fieldValue : value.values()) {
for (Map.Entry<String, FieldMappingMetaData> fieldMappingMetaDataEntry : fieldValue.entrySet()) {
if (fieldMappingMetaDataEntry.getValue() == FieldMappingMetaData.NULL) {
if (fieldMappingMetaDataEntry.getValue().isNull()) {
return true;
}
}
Expand Down

0 comments on commit dce39b0

Please sign in to comment.