ref #9629 cleanup t != null check and OptionalDataException check.
authorAndreas Müller <a.mueller@bgbm.org>
Tue, 6 Jul 2021 09:34:41 +0000 (11:34 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Tue, 6 Jul 2021 09:35:05 +0000 (11:35 +0200)
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java

index 718b4e52078ac3ec780842360ed72f550e48c5f8..c7b35206a348c20d992da50b2af9cf8c142e3dc4 100644 (file)
@@ -80,88 +80,74 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
                    if(statusAdapter.getStatus().matches(IStatus.ERROR)) {
 
                        Throwable t = statusAdapter.getStatus().getException();
-                       // NOTE : the global status handling mechanism in the case of
-                       //        runtime exceptions is called twice, once by the application
-                       //        throwing the exception and then by the rcp logging mechanism
-                       //        The check below is to make sure that the same exception is
-                       //        not shown twice in succession.
-                       if(t != null && previousT == t) {
-                       return;
-                   }
-                       previousT = t;
-
-                       if (t != null && t.getCause() instanceof PermissionDeniedException){
-                           MessagingUtils.informationDialog("Permission denied", MessagingUtils.PERMISSION_DENIED);
-                   }
-                       else if (t != null &&
-                               ( t instanceof NoHttpResponseException
-                                 || t.getCause() instanceof CdmAuthenticationException
-                                 || (t.getMessage() != null && t.getMessage().contains("status code = 403")))){
-                    MessagingUtils.informationDialog("Access denied", MessagingUtils.ACCESS_DENIED);
-                }else
-
-                       // NOTE : Currently we only allow RuntimeExceptions since
-                       //        allowing all kinds of exceptions would also include
-                       //        those in generated status objects coming from from logging triggers
-                       //        leading to a recursive infinite loop of :
-                       //        initial exception thrown -> status handling -> dialog opening + logging of status ->
-                       //        status handling -> dialog opening + logging of status ... and so on
-                       if(t != null &&
-                               t instanceof RuntimeException &&
-                               ! "Widget is disposed".equals(t.getMessage()) &&
-                               ! handleKnownRuntimeException(t,statusAdapter.getStatus().getPlugin())) {
-
-                           MessagingUtils.errorDialog("Error",
-                                   null,
-                                   MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
-                                   statusAdapter.getStatus().getPlugin(),
-                                   t,
-                                   true);
-
-                       } else if (t != null && ("Widget is disposed".equals(t.getMessage()))){
-                    MessagingUtils.warn(this.getClass(), t);
-                    if (PreferencesUtil.isShowUpWidgetIsDisposedMessages()){
-                        MessagingUtils.errorDialog("Widget is disposed",
-                                null,
-                                MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
-                                statusAdapter.getStatus().getPlugin(),
-                                t,
-                                true);
-                    }
-                }else {
-                    if (t != null){
-                        if (analyzeCauseExceptions(t)){
+                       if (t != null){
+                       // NOTE : the global status handling mechanism in the case of
+                       //        runtime exceptions is called twice, once by the application
+                       //        throwing the exception and then by the rcp logging mechanism.
+                       //        The check below is to make sure that the same exception is
+                       //        not shown twice in succession.
+                       if(previousT == t) {
+                       return;
+                   }
+                       previousT = t;
+
+                       if (t.getCause() instanceof PermissionDeniedException){
+                           MessagingUtils.informationDialog("Permission denied", MessagingUtils.PERMISSION_DENIED);
+                   }
+                       else if (t instanceof NoHttpResponseException
+                                 || t.getCause() instanceof CdmAuthenticationException
+                                 || (t.getMessage() != null && t.getMessage().contains("status code = 403"))){
+                        MessagingUtils.informationDialog("Access denied", MessagingUtils.ACCESS_DENIED);
+                    }else
+
+                       // NOTE : Currently we only allow RuntimeExceptions since
+                       //        allowing all kinds of exceptions would also include
+                       //        those in generated status objects coming from from logging triggers
+                       //        leading to a recursive infinite loop of :
+                       //        initial exception thrown -> status handling -> dialog opening + logging of status ->
+                       //        status handling -> dialog opening + logging of status ... and so on
+                       if(t instanceof RuntimeException &&
+                               ! "Widget is disposed".equals(t.getMessage()) &&
+                               ! handleKnownRuntimeException(t,statusAdapter.getStatus().getPlugin())) {
+
+                           MessagingUtils.errorDialog("Error",
+                                   null,
+                                   MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
+                                   statusAdapter.getStatus().getPlugin(),
+                                   t,
+                                   true);
+
+                       } else if (("Widget is disposed".equals(t.getMessage()))){
+                        MessagingUtils.warn(this.getClass(), t);
+                        if (PreferencesUtil.isShowUpWidgetIsDisposedMessages()){
+                            MessagingUtils.errorDialog("Widget is disposed",
+                                    null,
+                                    MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
+                                    statusAdapter.getStatus().getPlugin(),
+                                    t,
+                                    true);
+                        }
+                    }else {
+                        if (includesCause(t, OptionalDataException.class)){
                             MessagingUtils.warn(this.getClass(), MessagingUtils.RESTART_EDITOR_MESSAGE);
                         }
                     }
-                }
+                       }
                    }
                }
 
                /**
                 * analyzes whether the
-         * @param t
-         * @param class1
          */
-        private <T extends Exception>  boolean analyzeCauseExceptions(Throwable t) {
+        private <T extends Exception> boolean includesCause(Throwable t, Class<? extends Throwable> clazz) {
             boolean result = false;
 
-            if (t instanceof OptionalDataException || (t.getCause() != null && t.getCause() instanceof OptionalDataException)){
+            if (clazz.isAssignableFrom(t.getClass())){
                 return true;
             }else if (t.getCause() != null){
-                return analyzeCauseExceptions(t.getCause());
+                return includesCause(t.getCause(), clazz);
             }
             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) {