Project

General

Profile

« Previous | Next » 

Revision 9536f3f2

Added by Andreas Müller almost 3 years ago

ref #9629 cleanup t != null check and OptionalDataException check.

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java
80 80
		    if(statusAdapter.getStatus().matches(IStatus.ERROR)) {
81 81

  
82 82
		    	Throwable t = statusAdapter.getStatus().getException();
83
		    	// NOTE : the global status handling mechanism in the case of
84
		    	//        runtime exceptions is called twice, once by the application
85
		    	//        throwing the exception and then by the rcp logging mechanism
86
		    	//        The check below is to make sure that the same exception is
87
		    	//        not shown twice in succession.
88
		    	if(t != null && previousT == t) {
89
	                return;
90
	            }
91
		    	previousT = t;
92

  
93
		    	if (t != null && t.getCause() instanceof PermissionDeniedException){
94
		    	    MessagingUtils.informationDialog("Permission denied", MessagingUtils.PERMISSION_DENIED);
95
	            }
96
		    	else if (t != null &&
97
		    	        ( t instanceof NoHttpResponseException
98
		    	          || t.getCause() instanceof CdmAuthenticationException
99
		    	          || (t.getMessage() != null && t.getMessage().contains("status code = 403")))){
100
                    MessagingUtils.informationDialog("Access denied", MessagingUtils.ACCESS_DENIED);
101
                }else
102

  
103
		    	// NOTE : Currently we only allow RuntimeExceptions since
104
		    	//        allowing all kinds of exceptions would also include
105
		    	//        those in generated status objects coming from from logging triggers
106
		    	//        leading to a recursive infinite loop of :
107
		    	//        initial exception thrown -> status handling -> dialog opening + logging of status ->
108
		    	//        status handling -> dialog opening + logging of status ... and so on
109
		    	if(t != null &&
110
		    	        t instanceof RuntimeException &&
111
		    	        ! "Widget is disposed".equals(t.getMessage()) &&
112
		    	        ! handleKnownRuntimeException(t,statusAdapter.getStatus().getPlugin())) {
113

  
114
		    	    MessagingUtils.errorDialog("Error",
115
		    	            null,
116
		    	            MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
117
		    	            statusAdapter.getStatus().getPlugin(),
118
		    	            t,
119
		    	            true);
120

  
121
		    	} else if (t != null && ("Widget is disposed".equals(t.getMessage()))){
122
                    MessagingUtils.warn(this.getClass(), t);
123
                    if (PreferencesUtil.isShowUpWidgetIsDisposedMessages()){
124
                        MessagingUtils.errorDialog("Widget is disposed",
125
                                null,
126
                                MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
127
                                statusAdapter.getStatus().getPlugin(),
128
                                t,
129
                                true);
130
                    }
131
                }else {
132
                    if (t != null){
133
                        if (analyzeCauseExceptions(t)){
83
		    	if (t != null){
84
    		    	// NOTE : the global status handling mechanism in the case of
85
    		    	//        runtime exceptions is called twice, once by the application
86
    		    	//        throwing the exception and then by the rcp logging mechanism.
87
    		    	//        The check below is to make sure that the same exception is
88
    		    	//        not shown twice in succession.
89
    		    	if(previousT == t) {
90
    	                return;
91
    	            }
92
    		    	previousT = t;
93

  
94
    		    	if (t.getCause() instanceof PermissionDeniedException){
95
    		    	    MessagingUtils.informationDialog("Permission denied", MessagingUtils.PERMISSION_DENIED);
96
    	            }
97
    		    	else if (t instanceof NoHttpResponseException
98
    		    	          || t.getCause() instanceof CdmAuthenticationException
99
    		    	          || (t.getMessage() != null && t.getMessage().contains("status code = 403"))){
100
                        MessagingUtils.informationDialog("Access denied", MessagingUtils.ACCESS_DENIED);
101
                    }else
102

  
103
    		    	// NOTE : Currently we only allow RuntimeExceptions since
104
    		    	//        allowing all kinds of exceptions would also include
105
    		    	//        those in generated status objects coming from from logging triggers
106
    		    	//        leading to a recursive infinite loop of :
107
    		    	//        initial exception thrown -> status handling -> dialog opening + logging of status ->
108
    		    	//        status handling -> dialog opening + logging of status ... and so on
109
    		    	if(t instanceof RuntimeException &&
110
    		    	        ! "Widget is disposed".equals(t.getMessage()) &&
111
    		    	        ! handleKnownRuntimeException(t,statusAdapter.getStatus().getPlugin())) {
112

  
113
    		    	    MessagingUtils.errorDialog("Error",
114
    		    	            null,
115
    		    	            MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
116
    		    	            statusAdapter.getStatus().getPlugin(),
117
    		    	            t,
118
    		    	            true);
119

  
120
    		    	} else if (("Widget is disposed".equals(t.getMessage()))){
121
                        MessagingUtils.warn(this.getClass(), t);
122
                        if (PreferencesUtil.isShowUpWidgetIsDisposedMessages()){
123
                            MessagingUtils.errorDialog("Widget is disposed",
124
                                    null,
125
                                    MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
126
                                    statusAdapter.getStatus().getPlugin(),
127
                                    t,
128
                                    true);
129
                        }
130
                    }else {
131
                        if (includesCause(t, OptionalDataException.class)){
134 132
                            MessagingUtils.warn(this.getClass(), MessagingUtils.RESTART_EDITOR_MESSAGE);
135 133
                        }
136 134
                    }
137
                }
135
		    	}
138 136
		    }
139 137
		}
140 138

  
141 139
		/**
142 140
		 * analyzes whether the
143
         * @param t
144
         * @param class1
145 141
         */
146
        private <T extends Exception>  boolean analyzeCauseExceptions(Throwable t) {
142
        private <T extends Exception> boolean includesCause(Throwable t, Class<? extends Throwable> clazz) {
147 143
            boolean result = false;
148 144

  
149
            if (t instanceof OptionalDataException || (t.getCause() != null && t.getCause() instanceof OptionalDataException)){
145
            if (clazz.isAssignableFrom(t.getClass())){
150 146
                return true;
151 147
            }else if (t.getCause() != null){
152
                return analyzeCauseExceptions(t.getCause());
148
                return includesCause(t.getCause(), clazz);
153 149
            }
154 150
            return result;
155

  
156

  
157

  
158
//            if (t instanceof OptionalDataException || (t.getCause() != null && t.getCause() instanceof OptionalDataException)){
159
//                return true;
160
//            }else if (t.getCause() != null){
161
//                return analyzeCauseExceptions(t.getCause());
162
//            }
163
//            return result;
164

  
165 151
        }
166 152

  
167 153
        private boolean handleKnownRuntimeException(Throwable t, String pluginId) {

Also available in: Unified diff