From a869342910ccee00752d366d5dee2a23b3c065c0 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Wed, 7 Aug 2019 10:35:53 +0200 Subject: [PATCH] Restore DefaultShardOperationFailedException's reason after deserialization (#45203) The reason field of DefaultShardOperationFailedException is lost during serialization. This is sad because this field is checked for nullity during xcontent generation and it means that the cause won't be included in the generated xcontent and won't be printed in two REST API responses (Close Index API and Indices Shard Stores API). This commit simply restores the reason from the cause during deserialization. --- .../DefaultShardOperationFailedException.java | 1 + .../close/CloseIndexResponseTests.java | 1 + ...ultShardOperationFailedExceptionTests.java | 69 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java b/server/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java index cfdc463892f..7ac9965fa88 100644 --- a/server/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java +++ b/server/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java @@ -79,6 +79,7 @@ public class DefaultShardOperationFailedException extends ShardOperationFailedEx f.shardId = in.readVInt(); f.cause = in.readException(); f.status = RestStatus.readFrom(in); + f.reason = detailedMessage(f.cause); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java index 7ca56ecf14f..21f9844182f 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java @@ -113,6 +113,7 @@ public class CloseIndexResponseTests extends AbstractWireSerializingTestCase supplier = randomFrom( + () -> new CorruptIndexException(randomAlphaOfLengthBetween(1, 5), randomAlphaOfLengthBetween(1, 5), randomExceptionOrNull()), + () -> new NullPointerException(randomAlphaOfLengthBetween(1, 5)), + () -> new NumberFormatException(randomAlphaOfLengthBetween(1, 5)), + () -> new IllegalArgumentException(randomAlphaOfLengthBetween(1, 5), randomExceptionOrNull()), + () -> new AlreadyClosedException(randomAlphaOfLengthBetween(1, 5), randomExceptionOrNull()), + () -> new EOFException(randomAlphaOfLengthBetween(1, 5)), + () -> new SecurityException(randomAlphaOfLengthBetween(1, 5), randomExceptionOrNull()), + () -> new StringIndexOutOfBoundsException(randomAlphaOfLengthBetween(1, 5)), + () -> new ArrayIndexOutOfBoundsException(randomAlphaOfLengthBetween(1, 5)), + () -> new StringIndexOutOfBoundsException(randomAlphaOfLengthBetween(1, 5)), + () -> new FileNotFoundException(randomAlphaOfLengthBetween(1, 5)), + () -> new IllegalStateException(randomAlphaOfLengthBetween(1, 5), randomExceptionOrNull()), + () -> new LockObtainFailedException(randomAlphaOfLengthBetween(1, 5), randomExceptionOrNull()), + () -> new InterruptedException(randomAlphaOfLengthBetween(1, 5)), + () -> new IOException(randomAlphaOfLengthBetween(1, 5), randomExceptionOrNull()), + () -> new EsRejectedExecutionException(randomAlphaOfLengthBetween(1, 5), randomBoolean()), + () -> new IndexFormatTooNewException(randomAlphaOfLengthBetween(1, 10), randomInt(), randomInt(), randomInt()), + () -> new IndexFormatTooOldException(randomAlphaOfLengthBetween(1, 5), randomAlphaOfLengthBetween(1, 5)) + ); + return supplier.get(); + } + + private static Exception randomExceptionOrNull() { + return randomBoolean() ? randomException() : null; + } }