From 7567f4c8588f6b434938d1977080e97cfe47b6ba Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Wed, 2 Mar 2022 12:35:50 -0600 Subject: [PATCH] clean up GettMappingsResponse Signed-off-by: Nicholas Walter Knize --- .../indices/mapping/get/GetMappingsResponse.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java index b6624acd820aa..d203a5e6a45fe 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -65,13 +65,16 @@ public GetMappingsResponse(ImmutableOpenMap mappings) { String index = in.readString(); if (in.getVersion().before(Version.V_2_0_0)) { int mappingCount = in.readVInt(); - assert mappingCount == 1 || mappingCount == 0 : "Expected 0 or 1 mappings but got " + mappingCount; - if (mappingCount == 1) { + if (mappingCount == 0) { + indexMapBuilder.put(index, MappingMetadata.EMPTY_MAPPINGS); + } else if (mappingCount == 1) { String type = in.readString(); - assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got [" + type + "]"; + if (MapperService.SINGLE_MAPPING_NAME.equals(type) == false) { + throw new IllegalStateException("Expected " + MapperService.SINGLE_MAPPING_NAME + " but got [" + type + "]"); + } indexMapBuilder.put(index, new MappingMetadata(in)); } else { - indexMapBuilder.put(index, MappingMetadata.EMPTY_MAPPINGS); + throw new IllegalStateException("Expected 0 or 1 mappings but got: " + mappingCount); } } else { boolean hasMapping = in.readBoolean(); @@ -101,10 +104,7 @@ public void writeTo(StreamOutput out) throws IOException { indexEntry.value.writeTo(out); } } else { - out.writeBoolean(indexEntry.value != MappingMetadata.EMPTY_MAPPINGS); - if (indexEntry.value != MappingMetadata.EMPTY_MAPPINGS) { - indexEntry.value.writeTo(out); - } + out.writeOptionalWriteable(indexEntry.value); } } }