@Test public void testComposeCloseablesWithErrorOnSecond() { final int[] counter = new int[] { 0 }; final Closeable closeable1 = new Closeable() { @Override public void close() throws IOException { counter[0]++; } }; final Closeable closeable2 = new Closeable() { @Override public void close() throws IOException { counter[0]++; throw new AssertionError("ok"); } }; Runnable composed = Compose.closeables(closeable1, closeable2); try { composed.run(); } catch (AssertionError ex) { assertThat(ex.getMessage(), is("ok")); } assertThat(counter[0], is(2)); }
public static Runnable closeables(final Closeable a, final Closeable b) { return new Runnable() { @Override public void run() { try { a.close(); } catch (Throwable e1) { try { b.close(); } catch (Throwable ignore) { } handleException(e1); } try { b.close(); } catch (Throwable e2) { handleException(e2); } } }; }
Compose { public static Runnable closeables(final Closeable a, final Closeable b) { return new Runnable() { @Override public void run() { try { a.close(); } catch (Throwable e1) { try { b.close(); } catch (Throwable ignore) { } handleException(e1); } try { b.close(); } catch (Throwable e2) { handleException(e2); } } }; } }
Compose { public static Runnable closeables(final Closeable a, final Closeable b) { return new Runnable() { @Override public void run() { try { a.close(); } catch (Throwable e1) { try { b.close(); } catch (Throwable ignore) { } handleException(e1); } try { b.close(); } catch (Throwable e2) { handleException(e2); } } }; } private  Compose(); }
Compose { public static Runnable closeables(final Closeable a, final Closeable b) { return new Runnable() { @Override public void run() { try { a.close(); } catch (Throwable e1) { try { b.close(); } catch (Throwable ignore) { } handleException(e1); } try { b.close(); } catch (Throwable e2) { handleException(e2); } } }; } private  Compose(); static Runnable runnables(final Runnable a, final Runnable b); static Runnable closeables(final Closeable a, final Closeable b); }
Compose { public static Runnable closeables(final Closeable a, final Closeable b) { return new Runnable() { @Override public void run() { try { a.close(); } catch (Throwable e1) { try { b.close(); } catch (Throwable ignore) { } handleException(e1); } try { b.close(); } catch (Throwable e2) { handleException(e2); } } }; } private  Compose(); static Runnable runnables(final Runnable a, final Runnable b); static Runnable closeables(final Closeable a, final Closeable b);  }