From 2c67ba8f1a99336c52e1fc1e9b713471055cf508 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Thu, 30 Jan 2014 10:39:18 +0100 Subject: [PATCH] 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. --- .../admin/indices/mapping/get/GetFieldMappingsResponse.java | 4 ++++ .../admin/indices/mapping/get/RestGetFieldMappingAction.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java index 470ed6c4e247d..bd55901b9df05 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java @@ -108,6 +108,10 @@ public Map 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); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java index 43969c690a8e5..4ac48c0b855f3 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java @@ -119,7 +119,7 @@ private boolean isFieldMappingMissingField(ImmutableMap> value : mappingsByIndex.values()) { for (ImmutableMap fieldValue : value.values()) { for (Map.Entry fieldMappingMetaDataEntry : fieldValue.entrySet()) { - if (fieldMappingMetaDataEntry.getValue() == FieldMappingMetaData.NULL) { + if (fieldMappingMetaDataEntry.getValue().isNull()) { return true; } }