ref #9629: iterate over causes of exception
authorKatja Luther <k.luther@bgbm.org>
Fri, 11 Jun 2021 09:13:40 +0000 (11:13 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 11 Jun 2021 09:13:40 +0000 (11:13 +0200)
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java

index 231de8ebeed746a0f03e3bf5bf59bc284be05ee0..718b4e52078ac3ec780842360ed72f550e48c5f8 100644 (file)
@@ -1,6 +1,8 @@
 package eu.etaxonomy.taxeditor;
 
 
+import java.io.OptionalDataException;
+
 import org.apache.http.NoHttpResponseException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.ui.application.IWorkbenchConfigurer;
@@ -87,6 +89,7 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
                        return;
                    }
                        previousT = t;
+
                        if (t != null && t.getCause() instanceof PermissionDeniedException){
                            MessagingUtils.informationDialog("Permission denied", MessagingUtils.PERMISSION_DENIED);
                    }
@@ -125,13 +128,43 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
                                 t,
                                 true);
                     }
-                }else if (t != null && t.getStackTrace().toString().contains("java.io.OptionalDataException")){
-                    MessagingUtils.warn(this.getClass(), MessagingUtils.RESTART_EDITOR_MESSAGE);
+                }else {
+                    if (t != null){
+                        if (analyzeCauseExceptions(t)){
+                            MessagingUtils.warn(this.getClass(), MessagingUtils.RESTART_EDITOR_MESSAGE);
+                        }
+                    }
                 }
                    }
                }
 
-               private boolean handleKnownRuntimeException(Throwable t, String pluginId) {
+               /**
+                * analyzes whether the
+         * @param t
+         * @param class1
+         */
+        private <T extends Exception>  boolean analyzeCauseExceptions(Throwable t) {
+            boolean result = false;
+
+            if (t instanceof OptionalDataException || (t.getCause() != null && t.getCause() instanceof OptionalDataException)){
+                return true;
+            }else if (t.getCause() != null){
+                return analyzeCauseExceptions(t.getCause());
+            }
+            return result;
+
+
+
+//            if (t instanceof OptionalDataException || (t.getCause() != null && t.getCause() instanceof OptionalDataException)){
+//                return true;
+//            }else if (t.getCause() != null){
+//                return analyzeCauseExceptions(t.getCause());
+//            }
+//            return result;
+
+        }
+
+        private boolean handleKnownRuntimeException(Throwable t, String pluginId) {
                    if(t instanceof RemoteConnectFailureException ||
                            t.getCause() instanceof RemoteConnectFailureException) {
                        MessagingUtils.errorDialog("Connection Failure",