diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 16b6df065a8..978ac1185a9 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -181,7 +181,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte /** * Retruns true iff the given name is a registered for an exception to be read. */ - static boolean isRegistered(String name) { + public static boolean isRegistered(String name) { return MAPPING.containsKey(name); } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index da6ab25e65f..fc4726d6c28 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -473,7 +473,8 @@ public abstract class StreamOutput extends OutputStream { writeVInt(9); } else { ElasticsearchException ex; - if (throwable instanceof ElasticsearchException) { + final String name = throwable.getClass().getName(); + if (throwable instanceof ElasticsearchException && ElasticsearchException.isRegistered(name)) { ex = (ElasticsearchException) throwable; } else { ex = new NotSerializableExceptionWrapper(throwable);