@@ -70,15 +70,7 @@ public void setErrorHandlers(Map<Class<? extends Throwable>, CommonErrorHandler>
70
70
Assert .notNull (delegates , "'delegates' cannot be null" );
71
71
this .delegates .clear ();
72
72
this .delegates .putAll (delegates );
73
- checkDelegates ();
74
- updateClassifier (delegates );
75
- }
76
-
77
- private void updateClassifier (Map <Class <? extends Throwable >, CommonErrorHandler > delegates ) {
78
- Map <Class <? extends Throwable >, Boolean > classifications = delegates .keySet ().stream ()
79
- .map (commonErrorHandler -> Map .entry (commonErrorHandler , true ))
80
- .collect (Collectors .toMap (Entry ::getKey , Entry ::getValue ));
81
- this .classifier = new BinaryExceptionClassifier (classifications );
73
+ checkDelegatesAndUpdateClassifier (this .delegates );
82
74
}
83
75
84
76
/**
@@ -119,12 +111,17 @@ public void setAckAfterHandle(boolean ack) {
119
111
* @param handler the handler.
120
112
*/
121
113
public void addDelegate (Class <? extends Throwable > throwable , CommonErrorHandler handler ) {
122
- this .delegates .put (throwable , handler );
123
- checkDelegates ();
114
+ Map <Class <? extends Throwable >, CommonErrorHandler > delegatesToCheck = new LinkedHashMap <>(this .delegates );
115
+ delegatesToCheck .put (throwable , handler );
116
+ checkDelegatesAndUpdateClassifier (delegatesToCheck );
117
+ this .delegates .clear ();
118
+ this .delegates .putAll (delegatesToCheck );
124
119
}
125
120
126
121
@ SuppressWarnings ("deprecation" )
127
- private void checkDelegates () {
122
+ private void checkDelegatesAndUpdateClassifier (Map <Class <? extends Throwable >,
123
+ CommonErrorHandler > delegatesToCheck ) {
124
+
128
125
boolean ackAfterHandle = this .defaultErrorHandler .isAckAfterHandle ();
129
126
boolean seeksAfterHandling = this .defaultErrorHandler .seeksAfterHandling ();
130
127
this .delegates .values ().forEach (handler -> {
@@ -133,6 +130,14 @@ private void checkDelegates() {
133
130
Assert .isTrue (seeksAfterHandling == handler .seeksAfterHandling (),
134
131
"All delegates must return the same value when calling 'seeksAfterHandling()'" );
135
132
});
133
+ updateClassifier (delegatesToCheck );
134
+ }
135
+
136
+ private void updateClassifier (Map <Class <? extends Throwable >, CommonErrorHandler > delegates ) {
137
+ Map <Class <? extends Throwable >, Boolean > classifications = delegates .keySet ().stream ()
138
+ .map (commonErrorHandler -> Map .entry (commonErrorHandler , true ))
139
+ .collect (Collectors .toMap (Entry ::getKey , Entry ::getValue ));
140
+ this .classifier = new BinaryExceptionClassifier (classifications );
136
141
}
137
142
138
143
@ Override
0 commit comments