- return new AutoCloseable() {
- @Override
- public void close() throws Exception {
- Exception firstException = null;
- for (ListIterator<? extends AutoCloseable> it = list.listIterator(list.size()); it.hasPrevious();) {
- AutoCloseable ac = it.previous();
- try {
- ac.close();
- } catch (Exception e) {
- LOGGER.warn("Exception while closing {}", ac, e);
- if (firstException == null) {
- firstException = e;
- } else {
- firstException.addSuppressed(e);
- }
+ return () -> {
+ Exception firstException = null;
+ for (ListIterator<? extends AutoCloseable> it = list.listIterator(list.size()); it.hasPrevious();) {
+ AutoCloseable ac = it.previous();
+ try {
+ ac.close();
+ } catch (Exception e) {
+ LOG.warn("Exception while closing {}", ac, e);
+ if (firstException == null) {
+ firstException = e;
+ } else {
+ firstException.addSuppressed(e);