tillrohrmann commented on a change in pull request #9742: [FLINK-14076] Ensure 
CheckpointException can always be deserialized on JobManager
URL: https://github.com/apache/flink/pull/9742#discussion_r327577455
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -314,6 +314,37 @@ else if (t instanceof Error) {
                }
        }
 
+       /**
+        * Checks whether a throwable chain contains a specific type of 
exception and returns it. It deserializes
+        * any {@link SerializedThrowable} that are found.
+        *
+        * @param throwable the throwable chain to check.
+        * @param searchType the type of exception to search for in the chain.
+        * @return Optional throwable of the requested type if available, 
otherwise empty
+        */
+       public static <T extends Throwable> Optional<T> 
findSerializedThrowable(Throwable throwable, Class<T> searchType) {
+               if (throwable == null || searchType == null) {
+                       return Optional.empty();
+               }
+
+               Throwable t = throwable;
+               while (t != null) {
+                       if (searchType.isAssignableFrom(t.getClass())) {
+                               return Optional.of(searchType.cast(t));
+                       } else if 
(t.getClass().isAssignableFrom(SerializedThrowable.class)) {
+                               Throwable next = ((SerializedThrowable) 
t).deserializeError(ClassLoader.getSystemClassLoader());
 
 Review comment:
   I would pass in the class loader as a parameter because one might wanna use 
a user code class loader here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to