AbstractAutoClosingStream implements AutoCloseable { @Override public void close() { if (closed.compareAndSet(false,true)) { stream().close(); } } AbstractAutoClosingStream(
        final S stream,
        final boolean allowStreamIteratorAndSpliterator
    ); @Override void close();  }
@Test void testAutoCloseSingleCloseProperty() { final AtomicInteger cnt = new AtomicInteger(); try (S stream = createAutoclosableStream()) { stream.onClose(cnt::incrementAndGet); stream.close(); } assertEquals(1, cnt.get()); }