Skip to content

Commit 4b5b01f

Browse files
committed
Mapper: Throw exception if null_value is set to null
The mapping parser should throw an exception if "null_value" is set to `null`. Fixes #7273 ```bash PUT /foo { "mappings": { "bar": { "properties": { "exception": { "null_value": null, "type": "integer" } } } } } ``` ``` { "error": "MapperParsingException[mapping [bar]]; nested: MapperParsingException[Property [null_value] cannot be null.]; ", "status": 400 } ```
1 parent 635100a commit 4b5b01f

File tree

11 files changed

+95
-0
lines changed

11 files changed

+95
-0
lines changed

src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
111111
String propName = Strings.toUnderscoreCase(entry.getKey());
112112
Object propNode = entry.getValue();
113113
if (propName.equals("null_value")) {
114+
if (propNode == null) {
115+
throw new MapperParsingException("Property [null_value] cannot be null.");
116+
}
114117
builder.nullValue(nodeBooleanValue(propNode));
115118
}
116119
}

src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
108108
String propName = Strings.toUnderscoreCase(entry.getKey());
109109
Object propNode = entry.getValue();
110110
if (propName.equals("null_value")) {
111+
if (propNode == null) {
112+
throw new MapperParsingException("Property [null_value] cannot be null.");
113+
}
111114
builder.nullValue(nodeByteValue(propNode));
112115
}
113116
}

src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public static class TypeParser implements Mapper.TypeParser {
152152
String propName = Strings.toUnderscoreCase(entry.getKey());
153153
Object propNode = entry.getValue();
154154
if (propName.equals("null_value")) {
155+
if (propNode == null) {
156+
throw new MapperParsingException("Property [null_value] cannot be null.");
157+
}
155158
builder.nullValue(propNode.toString());
156159
} else if (propName.equals("format")) {
157160
builder.dateTimeFormatter(parseDateTimeFormatter(propNode));

src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
111111
String propName = entry.getKey();
112112
Object propNode = entry.getValue();
113113
if (propName.equals("nullValue") || propName.equals("null_value")) {
114+
if (propNode == null) {
115+
throw new MapperParsingException("Property [null_value] cannot be null.");
116+
}
114117
builder.nullValue(nodeDoubleValue(propNode));
115118
}
116119
}

src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
112112
String propName = Strings.toUnderscoreCase(entry.getKey());
113113
Object propNode = entry.getValue();
114114
if (propName.equals("null_value")) {
115+
if (propNode == null) {
116+
throw new MapperParsingException("Property [null_value] cannot be null.");
117+
}
115118
builder.nullValue(nodeFloatValue(propNode));
116119
}
117120
}

src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
108108
String propName = Strings.toUnderscoreCase(entry.getKey());
109109
Object propNode = entry.getValue();
110110
if (propName.equals("null_value")) {
111+
if (propNode == null) {
112+
throw new MapperParsingException("Property [null_value] cannot be null.");
113+
}
111114
builder.nullValue(nodeIntegerValue(propNode));
112115
}
113116
}

src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
108108
String propName = Strings.toUnderscoreCase(entry.getKey());
109109
Object propNode = entry.getValue();
110110
if (propName.equals("null_value")) {
111+
if (propNode == null) {
112+
throw new MapperParsingException("Property [null_value] cannot be null.");
113+
}
111114
builder.nullValue(nodeLongValue(propNode));
112115
}
113116
}

src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
110110
String propName = Strings.toUnderscoreCase(entry.getKey());
111111
Object propNode = entry.getValue();
112112
if (propName.equals("null_value")) {
113+
if (propNode == null) {
114+
throw new MapperParsingException("Property [null_value] cannot be null.");
115+
}
113116
builder.nullValue(nodeShortValue(propNode));
114117
}
115118
}

src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
155155
String propName = Strings.toUnderscoreCase(entry.getKey());
156156
Object propNode = entry.getValue();
157157
if (propName.equals("null_value")) {
158+
if (propNode == null) {
159+
throw new MapperParsingException("Property [null_value] cannot be null.");
160+
}
158161
builder.nullValue(propNode.toString());
159162
} else if (propName.equals("search_quote_analyzer")) {
160163
NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString());

src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
143143
String propName = Strings.toUnderscoreCase(entry.getKey());
144144
Object propNode = entry.getValue();
145145
if (propName.equals("null_value")) {
146+
if (propNode == null) {
147+
throw new MapperParsingException("Property [null_value] cannot be null.");
148+
}
146149
builder.nullValue(propNode.toString());
147150
}
148151
}

0 commit comments

Comments
 (0)