Removing and reordering ElasticsearchExceptions should be okay

This commit is contained in:
Jason Tedor 2015-09-25 14:43:40 -04:00
parent 752b4798d1
commit ab19bfbe9b
1 changed files with 4 additions and 6 deletions

View File

@ -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_TYPE_KEY = "es.resource.type";
private static final String RESOURCE_HEADER_ID_KEY = "es.resource.id"; private static final String RESOURCE_HEADER_ID_KEY = "es.resource.id";
private static final FunctionThatThrowsIOException<StreamInput, ? extends ElasticsearchException>[] ID_TO_SUPPLIER; private static final Map<Integer, FunctionThatThrowsIOException<StreamInput, ? extends ElasticsearchException>> ID_TO_SUPPLIER;
private static final Map<Class<? extends ElasticsearchException>, ElasticsearchExceptionHandle> CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE; private static final Map<Class<? extends ElasticsearchException>, ElasticsearchExceptionHandle> CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE;
private final Map<String, List<String>> headers = new HashMap<>(); private final Map<String, List<String>> headers = new HashMap<>();
@ -231,7 +231,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
} }
public static ElasticsearchException readException(StreamInput input, int id) throws IOException { public static ElasticsearchException readException(StreamInput input, int id) throws IOException {
FunctionThatThrowsIOException<StreamInput, ? extends ElasticsearchException> elasticsearchException = ID_TO_SUPPLIER[id]; FunctionThatThrowsIOException<StreamInput, ? extends ElasticsearchException> elasticsearchException = ID_TO_SUPPLIER.get(id);
if (elasticsearchException == null) { if (elasticsearchException == null) {
throw new IllegalStateException("unknown exception for id: " + id); throw new IllegalStateException("unknown exception for id: " + id);
} }
@ -613,11 +613,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
static { static {
final Map<Class<? extends ElasticsearchException>, ElasticsearchExceptionHandle> exceptions = Arrays.stream(ElasticsearchExceptionHandle.values()).collect(Collectors.toMap(e -> e.exceptionClass, e -> e)); final Map<Class<? extends ElasticsearchException>, ElasticsearchExceptionHandle> exceptions = Arrays.stream(ElasticsearchExceptionHandle.values()).collect(Collectors.toMap(e -> e.exceptionClass, e -> e));
final Map<Integer, FunctionThatThrowsIOException<StreamInput, ? extends ElasticsearchException>> idToSupplier = Arrays.stream(ElasticsearchExceptionHandle.values()).collect(Collectors.toMap(e -> e.id, e -> e.constructor));
FunctionThatThrowsIOException<StreamInput, ? extends ElasticsearchException>[] idToSupplier = new FunctionThatThrowsIOException[exceptions.size()]; ID_TO_SUPPLIER = Collections.unmodifiableMap(idToSupplier);
exceptions.entrySet().forEach(e -> idToSupplier[e.getValue().id] = e.getValue().constructor);
ID_TO_SUPPLIER = idToSupplier;
CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE = Collections.unmodifiableMap(exceptions); CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE = Collections.unmodifiableMap(exceptions);
} }