diff --git a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index 8330da04682..833eb92463a 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -411,8 +411,7 @@ public class InternalEngine extends Engine { * Inspects exception thrown when executing index or delete operations * * @return failure if the failure is a document specific failure (e.g. analysis chain failure) - * @throws ElasticsearchException if the failure caused the engine to fail - * (e.g. out of disk, lucene tragic event) + * or throws Exception if the failure caused the engine to fail (e.g. out of disk, lucene tragic event) * * Note: pkg-private for testing */ @@ -435,12 +434,16 @@ public class InternalEngine extends Engine { if (isDocumentFailure) { return failure; } else { - ElasticsearchException exception = new ElasticsearchException(failure); - exception.setShard(shardId); - throw exception; + rethrow(failure); + return null; } } + @SuppressWarnings("unchecked") + static void rethrow(Throwable t) throws T { + throw (T) t; + } + private boolean canOptimizeAddDocument(Index index) { if (index.getAutoGeneratedIdTimestamp() != IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP) { assert index.getAutoGeneratedIdTimestamp() >= 0 : "autoGeneratedIdTimestamp must be positive but was: " diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index be4b7bbdefe..bb2b7fe3aed 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -2153,9 +2153,8 @@ public class InternalEngineTests extends ESTestCase { try { engine.checkIfDocumentFailureOrThrow(new Engine.Index(newUid("1"), doc), new CorruptIndexException("simulated environment failure", "")); fail("expected exception to be thrown"); - } catch (ElasticsearchException envirnomentException) { - assertThat(envirnomentException.getShardId(), equalTo(engine.shardId)); - assertThat(envirnomentException.getCause().getMessage(), containsString("simulated environment failure")); + } catch (Exception envirnomentException) { + assertThat(envirnomentException.getMessage(), containsString("simulated environment failure")); } }