REST Get Field Mapping API: Fix NPE if field not existent

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.
This commit is contained in:
Alexander Reelsen 2014-01-30 10:39:18 +01:00
parent 79d1633dd6
commit 2c67ba8f1a
2 changed files with 5 additions and 1 deletions

View File

@ -108,6 +108,10 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
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);

View File

@ -119,7 +119,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
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;
}
}