瀏覽代碼

Remove unnecessary throws IOException in CompressedXContent.string() (#35821)

Dimitris Athanasiou 7 年之前
父節點
當前提交
43d6ec8bcd

+ 2 - 6
server/src/main/java/org/elasticsearch/common/compress/CompressedXContent.java

@@ -146,7 +146,7 @@ public final class CompressedXContent {
         }
     }
 
-    public String string() throws IOException {
+    public String string() {
         return new BytesRef(uncompressed()).utf8ToString();
     }
 
@@ -188,10 +188,6 @@ public final class CompressedXContent {
 
     @Override
     public String toString() {
-        try {
-            return string();
-        } catch (IOException e) {
-            return "_na_";
-        }
+        return string();
     }
 }

+ 1 - 7
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java

@@ -21,14 +21,12 @@ package org.elasticsearch.index.mapper;
 
 import com.carrotsearch.hppc.ObjectHashSet;
 import com.carrotsearch.hppc.cursors.ObjectCursor;
-
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
 import org.apache.lucene.index.Term;
 import org.elasticsearch.Assertions;
-import org.elasticsearch.ElasticsearchGenerationException;
 import org.elasticsearch.Version;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.cluster.metadata.MappingMetaData;
@@ -336,11 +334,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
             } catch (Exception e) {
                 throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, DEFAULT_MAPPING, e.getMessage());
             }
-            try {
-                defaultMappingSource = mappings.get(DEFAULT_MAPPING).string();
-            } catch (IOException e) {
-                throw new ElasticsearchGenerationException("failed to un-compress", e);
-            }
+            defaultMappingSource = mappings.get(DEFAULT_MAPPING).string();
         }
 
         final String defaultMappingSourceOrLastStored;

+ 5 - 9
server/src/main/java/org/elasticsearch/indices/IndicesService.java

@@ -613,15 +613,11 @@ public class IndicesService extends AbstractLifecycleComponent
             (type, mapping) -> {
                 assert recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS:
                     "mapping update consumer only required by local shards recovery";
-                try {
-                    client.admin().indices().preparePutMapping()
-                        .setConcreteIndex(shardRouting.index()) // concrete index - no name clash, it uses uuid
-                        .setType(type)
-                        .setSource(mapping.source().string(), XContentType.JSON)
-                        .get();
-                } catch (IOException ex) {
-                    throw new ElasticsearchException("failed to stringify mapping source", ex);
-                }
+                client.admin().indices().preparePutMapping()
+                    .setConcreteIndex(shardRouting.index()) // concrete index - no name clash, it uses uuid
+                    .setType(type)
+                    .setSource(mapping.source().string(), XContentType.JSON)
+                    .get();
             }, this);
         return indexShard;
     }