serialize as not-serializable if exception is not registered

This commit is contained in:
Simon Willnauer 2015-06-30 10:06:35 +02:00
parent 4e2621ca21
commit 325cc6bc61
2 changed files with 3 additions and 2 deletions

View File

@ -181,7 +181,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
/**
* Retruns <code>true</code> 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);
}

View File

@ -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);