From: Andreas Müller Date: Tue, 6 Jul 2021 09:34:41 +0000 (+0200) Subject: ref #9629 cleanup t != null check and OptionalDataException check. X-Git-Tag: 5.25.0^2~19 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/9536f3f25934a6ee7278d40345173d630da6636f ref #9629 cleanup t != null check and OptionalDataException check. --- diff --git a/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java b/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java index 718b4e520..c7b35206a 100644 --- a/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java +++ b/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java @@ -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 boolean analyzeCauseExceptions(Throwable t) { + private boolean includesCause(Throwable t, Class 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) {