From 828e31ce3279c214b290f227aa8e6e46be7cd26c Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 19 Aug 2015 10:00:30 +0200 Subject: [PATCH] Add serialization support for InterruptedException it's an important exception to serialize and we see it often in tests etc. but then it's wrapped in NotSerializableExceptionWrapper which is odd. This commit adds native support for this exception. --- .../common/io/stream/StreamInput.java | 2 ++ .../common/io/stream/StreamOutput.java | 3 +++ .../transport/netty/NettyTransport.java | 1 - .../ExceptionSerializationTests.java | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index cb42a9ff1b2..1b22a699913 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -542,6 +542,8 @@ public abstract class StreamInput extends InputStream { return (T) readStackTrace(new IllegalStateException(readOptionalString(), readThrowable()), this); case 17: return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readThrowable()), this); + case 18: + return (T) readStackTrace(new InterruptedException(readOptionalString()), this); default: assert false : "no such exception for id: " + key; } 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 afd607364c1..8ce9e24d6af 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 @@ -590,6 +590,9 @@ public abstract class StreamOutput extends OutputStream { writeVInt(16); } else if (throwable instanceof LockObtainFailedException) { writeVInt(17); + } else if (throwable instanceof InterruptedException) { + writeVInt(18); + writeCause = false; } else { ElasticsearchException ex; final String name = throwable.getClass().getName(); diff --git a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index 8a43e0581bd..e3f36bd24a3 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -497,7 +497,6 @@ public class NettyTransport extends AbstractLifecycleComponent implem serverBootstrap.setOption("child.receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory); serverBootstrap.setOption("reuseAddress", reuseAddress); serverBootstrap.setOption("child.reuseAddress", reuseAddress); - serverBootstraps.put(name, serverBootstrap); } diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 034d31c23f4..889901e549a 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -607,4 +607,20 @@ public class ExceptionSerializationTests extends ESTestCase { assertEquals(ex.status(), e.status()); assertEquals(RestStatus.UNAUTHORIZED, e.status()); } + + public void testInterruptedException() throws IOException { + InterruptedException orig = randomBoolean() ? new InterruptedException("boom") : new InterruptedException(); + InterruptedException ex = serialize(orig); + assertEquals(orig.getMessage(), ex.getMessage()); + } + + public static class UnknownException extends Exception { + public UnknownException(String message) { + super(message); + } + + public UnknownException(String message, Throwable cause) { + super(message, cause); + } + } }