From 0e14c6d2568c5e5ab15985fb525fb18c295a87f3 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 14 May 2015 14:36:26 -0700 Subject: [PATCH] Fix includes/excludes to be handled on merge conflict checking when they are null --- .../index/mapper/internal/SourceFieldMapper.java | 14 +++++++------- .../mapper/source/DefaultSourceMappingTests.java | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java index 5dd55356257..26513ddaeb6 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java @@ -222,24 +222,24 @@ public class SourceFieldMapper extends AbstractFieldMapper implements Ro this.enabled = enabled; this.compress = compress; this.compressThreshold = compressThreshold; - this.includes = includes; - this.excludes = excludes; + this.includes = includes == null ? Strings.EMPTY_ARRAY : includes; + this.excludes = excludes == null ? Strings.EMPTY_ARRAY : excludes; this.format = format; this.formatContentType = format == null ? null : XContentType.fromRestContentType(format); this.complete = enabled && includes == null && excludes == null; } public boolean enabled() { - return this.enabled; + return enabled; } public String[] excludes() { - return this.excludes != null ? this.excludes : Strings.EMPTY_ARRAY; + return excludes; } public String[] includes() { - return this.includes != null ? this.includes : Strings.EMPTY_ARRAY; + return includes; } public boolean isComplete() { @@ -433,10 +433,10 @@ public class SourceFieldMapper extends AbstractFieldMapper implements Ro if (this.enabled != sourceMergeWith.enabled) { mergeResult.addConflict("Cannot update enabled setting for [_source]"); } - if (Arrays.equals(this.includes, sourceMergeWith.includes) == false) { + if (Arrays.equals(includes, sourceMergeWith.includes) == false) { mergeResult.addConflict("Cannot update includes setting for [_source]"); } - if (Arrays.equals(this.excludes, sourceMergeWith.excludes) == false) { + if (Arrays.equals(excludes, sourceMergeWith.excludes) == false) { mergeResult.addConflict("Cannot update excludes setting for [_source]"); } } else { diff --git a/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java index 2516a3b42a2..25ab2a5c6c0 100644 --- a/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java @@ -253,9 +253,13 @@ public class DefaultSourceMappingTests extends ElasticsearchSingleNodeTest { public void testIncludesNotUpdateable() throws Exception { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("includes", "foo.*").endObject() .endObject().endObject().string(); + assertConflicts(defaultMapping, mapping1, parser, "Cannot update includes setting for [_source]"); + assertConflicts(mapping1, defaultMapping, parser, "Cannot update includes setting for [_source]"); + String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("includes", "foo.*", "bar.*").endObject() .endObject().endObject().string(); @@ -267,9 +271,13 @@ public class DefaultSourceMappingTests extends ElasticsearchSingleNodeTest { public void testExcludesNotUpdateable() throws Exception { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("excludes", "foo.*").endObject() .endObject().endObject().string(); + assertConflicts(defaultMapping, mapping1, parser, "Cannot update excludes setting for [_source]"); + assertConflicts(mapping1, defaultMapping, parser, "Cannot update excludes setting for [_source]"); + String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("excludes", "foo.*", "bar.*").endObject() .endObject().endObject().string();