22
33import io .github .notstirred .chunkyeditor .VanillaRegionPos ;
44import io .github .notstirred .chunkyeditor .state .State ;
5+ import io .github .notstirred .chunkyeditor .util .ExceptionUtils ;
56import se .llbit .util .Pair ;
67import se .llbit .util .annotation .NotNull ;
78import se .llbit .util .annotation .Nullable ;
@@ -115,7 +116,7 @@ private StateGroup snapshot(Collection<VanillaRegionPos> regionPositions) throws
115116 */
116117 @ NotNull
117118 private Pair <StateGroup , IOException > snapshotNoFail (Collection <VanillaRegionPos > regionPositions ) {
118- IOException suppressedExceptions = null ;
119+ Collection < IOException > suppressedExceptions = new ArrayList <>() ;
119120
120121 StateGroup states = new StateGroup ();
121122 if (this .currentStateIdx == NO_STATE ) {
@@ -124,11 +125,7 @@ private Pair<StateGroup, IOException> snapshotNoFail(Collection<VanillaRegionPos
124125 try {
125126 states .put (regionPos , externalStateForRegion (regionPos ));
126127 } catch (IOException e ) {
127- if (suppressedExceptions == null ) {
128- suppressedExceptions = e ;
129- } else {
130- suppressedExceptions .addSuppressed (e );
131- }
128+ suppressedExceptions .add (e );
132129 states .put (regionPos , null );
133130 }
134131 }
@@ -145,11 +142,7 @@ private Pair<StateGroup, IOException> snapshotNoFail(Collection<VanillaRegionPos
145142 try {
146143 externalState = externalStateForRegion (regionPos );
147144 } catch (IOException e ) {
148- if (suppressedExceptions == null ) {
149- suppressedExceptions = e ;
150- } else {
151- suppressedExceptions .addSuppressed (e );
152- }
145+ suppressedExceptions .add (e );
153146 continue ; // we failed to snapshot this region, continue to the next ones.
154147 }
155148
@@ -164,17 +157,13 @@ private Pair<StateGroup, IOException> snapshotNoFail(Collection<VanillaRegionPos
164157 }
165158 }
166159 } catch (IOException e ) {
167- if (suppressedExceptions == null ) {
168- suppressedExceptions = e ;
169- } else {
170- suppressedExceptions .addSuppressed (e );
171- }
160+ suppressedExceptions .add (e );
172161 }
173162 }
174163 states .put (regionPos , externalState );
175164 }
176165 }
177- return new Pair <>(states , suppressedExceptions );
166+ return new Pair <>(states , ExceptionUtils . chainSuppressedExceptions ( suppressedExceptions ) );
178167 }
179168
180169 /**
0 commit comments