Skip to content

Commit 2c67ba8

Browse files
committed
REST Get Field Mapping API: Fix NPE if field not existent
When fixing elastic#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.
1 parent 79d1633 commit 2c67ba8

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public Map<String, Object> sourceAsMap() {
108108
return XContentHelper.convertToMap(source.array(), source.arrayOffset(), source.length(), true).v2();
109109
}
110110

111+
public boolean isNull() {
112+
return NULL.fullName().equals(fullName) && NULL.source.length() == source.length();
113+
}
114+
111115
@Override
112116
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
113117
builder.field("full_name", fullName);

src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private boolean isFieldMappingMissingField(ImmutableMap<String, ImmutableMap<Str
119119
for (ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>> value : mappingsByIndex.values()) {
120120
for (ImmutableMap<String, FieldMappingMetaData> fieldValue : value.values()) {
121121
for (Map.Entry<String, FieldMappingMetaData> fieldMappingMetaDataEntry : fieldValue.entrySet()) {
122-
if (fieldMappingMetaDataEntry.getValue() == FieldMappingMetaData.NULL) {
122+
if (fieldMappingMetaDataEntry.getValue().isNull()) {
123123
return true;
124124
}
125125
}

0 commit comments

Comments
 (0)