flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ches...@apache.org
Subject [4/7] flink git commit: [hotfix][utils] Add ExceptionUtils#findThrowable with predicate
Date Fri, 23 Mar 2018 18:12:51 GMT
[hotfix][utils] Add ExceptionUtils#findThrowable with predicate


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/555e5e8c
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/555e5e8c
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/555e5e8c

Branch: refs/heads/release-1.5
Commit: 555e5e8cd0a7b08457f65364ae62d13eb593fb44
Parents: 4ebbbe7
Author: zentol <chesnay@apache.org>
Authored: Tue Mar 20 11:38:24 2018 +0100
Committer: zentol <chesnay@apache.org>
Committed: Fri Mar 23 19:12:29 2018 +0100

----------------------------------------------------------------------
 .../org/apache/flink/util/ExceptionUtils.java   | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/555e5e8c/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java b/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
index 6af16fc..459648f 100644
--- a/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
+++ b/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
@@ -35,6 +35,7 @@ import java.io.StringWriter;
 import java.util.Optional;
 import java.util.concurrent.CompletionException;
 import java.util.concurrent.ExecutionException;
+import java.util.function.Predicate;
 
 import static org.apache.flink.util.Preconditions.checkNotNull;
 
@@ -326,6 +327,30 @@ public final class ExceptionUtils {
 	}
 
 	/**
+	 * Checks whether a throwable chain contains an exception matching a predicate and returns
it.
+	 *
+	 * @param throwable the throwable chain to check.
+	 * @param predicate the predicate of the exception to search for in the chain.
+	 * @return Optional throwable of the requested type if available, otherwise empty
+	 */
+	public static Optional<Throwable> findThrowable(Throwable throwable, Predicate<Throwable>
predicate) {
+		if (throwable == null || predicate == null) {
+			return Optional.empty();
+		}
+
+		Throwable t = throwable;
+		while (t != null) {
+			if (predicate.test(t)) {
+				return Optional.of(t);
+			} else {
+				t = t.getCause();
+			}
+		}
+
+		return Optional.empty();
+	}
+
+	/**
 	 * Checks whether a throwable chain contains a specific error message and returns the corresponding
throwable.
 	 *
 	 * @param throwable the throwable chain to check.


Mime
View raw message