@@ -181,25 +181,55 @@ public Properties getClientInfo() {
181181
182182 @ Override
183183 public void close () throws SQLException {
184- // Clean up any open Statements
184+ Exception topLevelException = null ;
185185 try {
186186 AutoCloseables .close (List .copyOf (statementMap .values ()));
187187 } catch (final Exception e ) {
188- throw AvaticaConnection .HELPER .createException (e .getMessage (), e );
188+ topLevelException = e ;
189+ }
190+ try {
191+ AutoCloseables .close (clientHandler );
192+ } catch (final Exception e ) {
193+ if (topLevelException == null ) {
194+ topLevelException = e ;
195+ } else {
196+ topLevelException .addSuppressed (e );
197+ }
189198 }
190- clientHandler .close ();
191- if (executorService != null ) {
192- executorService .shutdown ();
199+ try {
200+ if (executorService != null ) {
201+ executorService .shutdown ();
202+ }
203+ } catch (final Exception e ) {
204+ if (topLevelException == null ) {
205+ topLevelException = e ;
206+ } else {
207+ topLevelException .addSuppressed (e );
208+ }
193209 }
194210
195211 try {
196- AutoCloseables .close (clientHandler );
197212 allocator .getChildAllocators ().forEach (AutoCloseables ::closeNoChecked );
198213 AutoCloseables .close (allocator );
199-
214+ } catch (final Exception e ) {
215+ if (topLevelException == null ) {
216+ topLevelException = e ;
217+ } else {
218+ topLevelException .addSuppressed (e );
219+ }
220+ }
221+ try {
200222 super .close ();
201223 } catch (final Exception e ) {
202- throw AvaticaConnection .HELPER .createException (e .getMessage (), e );
224+ if (topLevelException == null ) {
225+ topLevelException = e ;
226+ } else {
227+ topLevelException .addSuppressed (e );
228+ }
229+ }
230+ if (topLevelException != null ) {
231+ throw AvaticaConnection .HELPER .createException (
232+ topLevelException .getMessage (), topLevelException );
203233 }
204234 }
205235
0 commit comments