11/*
2- * Copyright 2021-2022 the original author or authors.
2+ * Copyright 2021-2023 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -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 /**
@@ -125,12 +117,17 @@ public void setAckAfterHandle(boolean ack) {
125117 * @param handler the handler.
126118 */
127119 public void addDelegate (Class <? extends Throwable > throwable , CommonErrorHandler handler ) {
128- this .delegates .put (throwable , handler );
129- checkDelegates ();
120+ Map <Class <? extends Throwable >, CommonErrorHandler > delegatesToCheck = new LinkedHashMap <>(this .delegates );
121+ delegatesToCheck .put (throwable , handler );
122+ checkDelegatesAndUpdateClassifier (delegatesToCheck );
123+ this .delegates .clear ();
124+ this .delegates .putAll (delegatesToCheck );
130125 }
131126
132127 @ SuppressWarnings ("deprecation" )
133- private void checkDelegates () {
128+ private void checkDelegatesAndUpdateClassifier (Map <Class <? extends Throwable >,
129+ CommonErrorHandler > delegatesToCheck ) {
130+
134131 boolean remainingRecords = this .defaultErrorHandler .remainingRecords ();
135132 boolean ackAfterHandle = this .defaultErrorHandler .isAckAfterHandle ();
136133 boolean seeksAfterHandling = this .defaultErrorHandler .seeksAfterHandling ();
@@ -142,6 +139,14 @@ private void checkDelegates() {
142139 Assert .isTrue (seeksAfterHandling == handler .seeksAfterHandling (),
143140 "All delegates must return the same value when calling 'seeksAfterHandling()'" );
144141 });
142+ updateClassifier (delegatesToCheck );
143+ }
144+
145+ private void updateClassifier (Map <Class <? extends Throwable >, CommonErrorHandler > delegates ) {
146+ Map <Class <? extends Throwable >, Boolean > classifications = delegates .keySet ().stream ()
147+ .map (commonErrorHandler -> Map .entry (commonErrorHandler , true ))
148+ .collect (Collectors .toMap (Entry ::getKey , Entry ::getValue ));
149+ this .classifier = new BinaryExceptionClassifier (classifications );
145150 }
146151
147152 @ Override
0 commit comments