Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11571: commons: add Closer class (similar to Guava Closer) #2181

Open
wants to merge 16 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
1b60437
OAK-11571: commons: add Closer class (similar to Guava Closer) - tests
reschke Mar 8, 2025
a185bdf
OAK-11571: commons: add Closer class (similar to Guava Closer) - tests
reschke Mar 8, 2025
31a4ff1
OAK-11571: commons: add Closer class (similar to Guava Closer) - more…
reschke Mar 12, 2025
80fd312
OAK-11571: commons: add Closer class (similar to Guava Closer) - add …
reschke Mar 13, 2025
9c6beb5
OAK-11571: commons: add Closer class (similar to Guava Closer) - fix …
reschke Mar 13, 2025
70e994e
add missibng return value and 'implements' - no test coverage yet
reschke Mar 13, 2025
5912f06
OAK-11571: commons: add Closer class (similar to Guava Closer) - add …
reschke Mar 13, 2025
d985207
Revert "OAK-11571: commons: add Closer class (similar to Guava Closer…
reschke Mar 13, 2025
70839c2
OAK-11571: commons: add Closer class (similar to Guava Closer) - add …
reschke Mar 13, 2025
d254e8f
OAK-11571: commons: add Closer class (similar to Guava Closer) - move…
reschke Mar 13, 2025
ede89da
Merge branch 'trunk' into OAK-11571
reschke Mar 14, 2025
72f5375
OAK-11571: commons: add Closer class (similar to Guava Closer) - make…
reschke Mar 14, 2025
251ba53
OAK-11571: commons: add Closer class (similar to Guava Closer) - reth…
reschke Mar 14, 2025
0e6134a
OAK-11571: commons: add Closer class (similar to Guava Closer) - Javadoc
reschke Mar 14, 2025
7abc5cd
OAK-11571: commons: add Closer class (similar to Guava Closer) - Dequ…
reschke Mar 14, 2025
1c4faf2
OAK-11571: commons: add Closer class (similar to Guava Closer - handl…
reschke Mar 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
OAK-11571: commons: add Closer class (similar to Guava Closer) - Javadoc
reschke committed Mar 14, 2025
commit 0e6134a99c9b6aa4dffb07f3d6ec18f8ad23e144
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@
import java.util.Objects;

/**
* Convenience utility to close a list of {@link Closeable}s.
* Convenience utility to close a list of {@link Closeable}s in reverse order,
* suppressing all but the first exception to occur.
* <p>
* Inspired by and replacing Guava's Closer.
*/
@@ -41,8 +42,9 @@ private Closer() {
// stack of closeables to close
private final Deque<Closeable> closeables = new ArrayDeque<>();

// set by rethrow method
// flag set by rethrow method
private boolean suppressExceptionsOnClose = false;

/**
* Create instance of Closer.
*/
@@ -68,9 +70,8 @@ public static Closer create() {
* Swallows all {@link IOException}s except the first that
* was thrown.
* <p>
* If {@link #rethrow} was called before, throw <em>that</em>
* exception instead (wrapped into a {@link RuntimeException}
* when necessary).
* If {@link #rethrow} was called before, even the first
* exception will be suppressed.
*/
public void close() throws IOException {
// keep track of the IOException to throw
@@ -97,7 +98,7 @@ public void close() throws IOException {

/**
* Sets a flag indicating that this method was called, then rethrows the
* given exception.
* given exception (potentially wrapped into {@link Error} or {@link RuntimeException}).
* <p>
* {@link #close()} will not throw when this method was called before.
* @return never returns