You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2018/04/13 09:33:47 UTC
[35/54] [abbrv] ignite git commit: IGNITE-8106 Collect suppressed
exceptions from causes. - Fixes #3735.
IGNITE-8106 Collect suppressed exceptions from causes. - Fixes #3735.
Signed-off-by: Alexey Kuznetsov <ak...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/98ef9259
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/98ef9259
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/98ef9259
Branch: refs/heads/ignite-6083
Commit: 98ef925933f392d419f70b2fcf51e3655b08b290
Parents: a3eb1f5
Author: Ilya Kasnacheev <il...@gmail.com>
Authored: Wed Apr 11 19:32:52 2018 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Wed Apr 11 19:32:52 2018 +0700
----------------------------------------------------------------------
.../cluster/GridChangeStateCommandHandler.java | 3 +-
.../apache/ignite/internal/util/typedef/X.java | 37 +++++++++++++++-----
.../visor/util/VisorExceptionWrapper.java | 11 +++---
.../communication/tcp/TcpCommunicationSpi.java | 2 +-
.../ignite/GridSuppressedExceptionSelfTest.java | 23 +++++++++++-
5 files changed, 59 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef9259/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
index 7bb13d9..619be34 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
@@ -27,6 +27,7 @@ import org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandle
import org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest;
import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -78,7 +79,7 @@ public class GridChangeStateCommandHandler extends GridRestCommandHandlerAdapter
sb.a(e.getMessage()).a("\n").a("suppressed: \n");
- for (Throwable t:e.getSuppressed())
+ for (Throwable t : X.getSuppressedList(e))
sb.a(t.getMessage()).a("\n");
res.setError(sb.toString());
http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef9259/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java
index 395de23..1a43daa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/X.java
@@ -469,14 +469,12 @@ public final class X {
if (t == null || cls == null)
return false;
- if (t.getSuppressed() != null) {
- for (Throwable th : t.getSuppressed()) {
- if (cls.isAssignableFrom(th.getClass()))
- return true;
+ for (Throwable th : t.getSuppressed()) {
+ if (cls.isAssignableFrom(th.getClass()))
+ return true;
- if (hasSuppressed(th, cls))
- return true;
- }
+ if (hasSuppressed(th, cls))
+ return true;
}
return false;
@@ -749,6 +747,29 @@ public final class X {
}
/**
+ * Collects suppressed exceptions from throwable and all it causes.
+ *
+ * @param t Throwable.
+ * @return List of suppressed throwables.
+ */
+ public static List<Throwable> getSuppressedList(@Nullable Throwable t) {
+ List<Throwable> result = new ArrayList<>();
+
+ if (t == null)
+ return result;
+
+ do {
+ for (Throwable suppressed : t.getSuppressed()) {
+ result.add(suppressed);
+
+ result.addAll(getSuppressedList(suppressed));
+ }
+ } while ((t = t.getCause()) != null);
+
+ return result;
+ }
+
+ /**
* A way to get the entire nested stack-trace of an throwable.
*
* The result of this method is highly dependent on the JDK version
@@ -889,4 +910,4 @@ public final class X {
return dflt;
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef9259/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java
index 15e9557..ba52c5f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorExceptionWrapper.java
@@ -17,7 +17,8 @@
package org.apache.ignite.internal.visor.util;
-import org.apache.ignite.internal.util.typedef.F;
+import java.util.List;
+import org.apache.ignite.internal.util.typedef.X;
/**
* Exception wrapper for safe for transferring to Visor.
@@ -56,12 +57,10 @@ public class VisorExceptionWrapper extends Throwable {
if (cause.getCause() != null)
initCause(new VisorExceptionWrapper(cause.getCause()));
- Throwable[] suppressed = cause.getSuppressed();
+ List<Throwable> suppressed = X.getSuppressedList(cause);
- if (!F.isEmpty(suppressed)) {
- for (Throwable sup : suppressed)
- addSuppressed(new VisorExceptionWrapper(sup));
- }
+ for (Throwable sup : suppressed)
+ addSuppressed(new VisorExceptionWrapper(sup));
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef9259/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index 9e7b592..df37dff 100755
--- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -3476,7 +3476,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter implements Communicati
ctx.failNode(node.id(), "TcpCommunicationSpi failed to establish connection to node [" +
"rmtNode=" + node +
", errs=" + errs +
- ", connectErrs=" + Arrays.toString(errs.getSuppressed()) + ']');
+ ", connectErrs=" + X.getSuppressedList(errs) + ']');
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef9259/modules/core/src/test/java/org/apache/ignite/GridSuppressedExceptionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/GridSuppressedExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/GridSuppressedExceptionSelfTest.java
index 6e32249..55e54fb 100644
--- a/modules/core/src/test/java/org/apache/ignite/GridSuppressedExceptionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/GridSuppressedExceptionSelfTest.java
@@ -18,6 +18,7 @@
package org.apache.ignite;
import java.io.IOException;
+import java.util.List;
import junit.framework.TestCase;
import org.apache.ignite.internal.util.typedef.X;
@@ -70,6 +71,26 @@ public class GridSuppressedExceptionSelfTest extends TestCase {
/**
* @throws Exception If failed.
*/
+ public void testXGetSuppressedList() throws Exception {
+ IgniteCheckedException me = prepareMultiException();
+
+ assertEquals(3, X.getSuppressedList(me).size());
+
+ RuntimeException e = new RuntimeException();
+ e.addSuppressed(me);
+
+ List<Throwable> suppresseds = X.getSuppressedList(e);
+
+ assertEquals(4, suppresseds.size());
+
+ assertEquals("Test message.", suppresseds.get(0).getMessage());
+ for (int i = 1; i <= 3; i++)
+ assertEquals("Demo exception.", suppresseds.get(1).getMessage());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
public void testXCause() throws Exception {
IgniteCheckedException me = prepareMultiException();
@@ -116,4 +137,4 @@ public class GridSuppressedExceptionSelfTest extends TestCase {
else
generateException(calls - 1, cause);
}
-}
\ No newline at end of file
+}