From ab19bfbe9b6edc9c907a6af20a256ef50bcb2e0f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 25 Sep 2015 14:43:40 -0400 Subject: [PATCH] Removing and reordering ElasticsearchExceptions should be okay --- .../java/org/elasticsearch/ElasticsearchException.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 7422ab7834d..d9ac0003a8e 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -47,7 +47,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte private static final String RESOURCE_HEADER_TYPE_KEY = "es.resource.type"; private static final String RESOURCE_HEADER_ID_KEY = "es.resource.id"; - private static final FunctionThatThrowsIOException[] ID_TO_SUPPLIER; + private static final Map> ID_TO_SUPPLIER; private static final Map, ElasticsearchExceptionHandle> CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE; private final Map> headers = new HashMap<>(); @@ -231,7 +231,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } public static ElasticsearchException readException(StreamInput input, int id) throws IOException { - FunctionThatThrowsIOException elasticsearchException = ID_TO_SUPPLIER[id]; + FunctionThatThrowsIOException elasticsearchException = ID_TO_SUPPLIER.get(id); if (elasticsearchException == null) { throw new IllegalStateException("unknown exception for id: " + id); } @@ -613,11 +613,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte static { final Map, ElasticsearchExceptionHandle> exceptions = Arrays.stream(ElasticsearchExceptionHandle.values()).collect(Collectors.toMap(e -> e.exceptionClass, e -> e)); + final Map> idToSupplier = Arrays.stream(ElasticsearchExceptionHandle.values()).collect(Collectors.toMap(e -> e.id, e -> e.constructor)); - FunctionThatThrowsIOException[] idToSupplier = new FunctionThatThrowsIOException[exceptions.size()]; - exceptions.entrySet().forEach(e -> idToSupplier[e.getValue().id] = e.getValue().constructor); - - ID_TO_SUPPLIER = idToSupplier; + ID_TO_SUPPLIER = Collections.unmodifiableMap(idToSupplier); CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE = Collections.unmodifiableMap(exceptions); }