From 60a6e4d4794a902b84eff8127baa6efa0b6ad14d Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 30 Dec 2019 16:04:05 +0100 Subject: [PATCH] Guess root cause support unwrap ElasticsearchException.guessRootCauses would return wrapper exception if inner exception was not an ElasticsearchException. Fixed to never return wrapper exceptions. Relates #50417 --- .../java/org/elasticsearch/ElasticsearchException.java | 2 +- .../org/elasticsearch/ElasticsearchExceptionTests.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/ElasticsearchException.java b/server/src/main/java/org/elasticsearch/ElasticsearchException.java index abaceff4f4e73..f588823f699b3 100644 --- a/server/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/server/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -641,7 +641,7 @@ public static ElasticsearchException[] guessRootCauses(Throwable t) { } } } - return new ElasticsearchException[]{new ElasticsearchException(t.getMessage(), t) { + return new ElasticsearchException[]{new ElasticsearchException(ex.getMessage(), ex) { @Override protected String getExceptionName() { return getExceptionName(getCause()); diff --git a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index 9ed826de87cdd..570598831f944 100644 --- a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -163,6 +163,16 @@ public void testGuessRootCause() { assertEquals("illegal_argument_exception", foobars[0].getExceptionName()); } + { + final ElasticsearchException[] foobars = ElasticsearchException.guessRootCauses( + new RemoteTransportException("abc", new IllegalArgumentException("foobar"))); + assertEquals(foobars.length, 1); + assertThat(foobars[0], instanceOf(ElasticsearchException.class)); + assertEquals("foobar", foobars[0].getMessage()); + assertEquals(IllegalArgumentException.class, foobars[0].getCause().getClass()); + assertEquals("illegal_argument_exception", foobars[0].getExceptionName()); + } + { XContentParseException inner = new XContentParseException(null, "inner"); XContentParseException outer = new XContentParseException(null, "outer", inner);