@@ -70,15 +70,7 @@ public void setErrorHandlers(Map<Class<? extends Throwable>, CommonErrorHandler>
7070 Assert .notNull (delegates , "'delegates' cannot be null" );
7171 this .delegates .clear ();
7272 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 );
8274 }
8375
8476 /**
@@ -119,12 +111,17 @@ public void setAckAfterHandle(boolean ack) {
119111 * @param handler the handler.
120112 */
121113 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 );
124119 }
125120
126121 @ SuppressWarnings ("deprecation" )
127- private void checkDelegates () {
122+ private void checkDelegatesAndUpdateClassifier (Map <Class <? extends Throwable >,
123+ CommonErrorHandler > delegatesToCheck ) {
124+
128125 boolean ackAfterHandle = this .defaultErrorHandler .isAckAfterHandle ();
129126 boolean seeksAfterHandling = this .defaultErrorHandler .seeksAfterHandling ();
130127 this .delegates .values ().forEach (handler -> {
@@ -133,6 +130,14 @@ private void checkDelegates() {
133130 Assert .isTrue (seeksAfterHandling == handler .seeksAfterHandling (),
134131 "All delegates must return the same value when calling 'seeksAfterHandling()'" );
135132 });
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 );
136141 }
137142
138143 @ Override
0 commit comments