Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 26 additions & 1 deletion common/src/main/java/org/apache/drill/common/AutoCloseables.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void close(AutoCloseable... autoCloseables) throws Exception {

/**
* Closes all autoCloseables if not null and suppresses subsequent exceptions if more than one
* @param autoCloseables the closeables to close
* @param ac the closeables to close
*/
public static void close(Iterable<? extends AutoCloseable> ac) throws Exception {
Exception topLevelException = null;
Expand All @@ -87,4 +87,29 @@ public static void close(Iterable<? extends AutoCloseable> ac) throws Exception
throw topLevelException;
}
}

/**
* close() an {@see java.lang.AutoCloseable} without throwing a (checked)
* {@see java.lang.Exception}. This wraps the close() call with a
* try-catch that will rethrow an Exception wrapped with a
* {@see java.lang.RuntimeException}, providing a way to call close()
* without having to do the try-catch everywhere or propagate the Exception.
*
* @param autoCloseable the AutoCloseable to close; may be null
* @throws RuntimeException if an Exception occurs; the Exception is
* wrapped by the RuntimeException
*/
public static void closeNoChecked(final AutoCloseable autoCloseable) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closeUnchecked ?

But, we are "checking", the "checked" has to do with the Exception type.

Maybe cleanClose( ) for this function. Then, add a "closeSilently" to catch and ignore close exceptions. (The closeSilently is handy in the case when, say, a file is full, a write failed, and the close will also fail because it still can't flush pending buffers.) There are other functions to the to silent close, but might be handy to have them in one place.

if (autoCloseable != null) {
try {
autoCloseable.close();
} catch(final Exception e) {
throw new RuntimeException("Exception while closing", e);
}
}
}

// prevents instantiation
private AutoCloseables() {
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public class TestHBaseCFAsJSONString extends BaseHBaseTest {
@BeforeClass
public static void openMyClient() throws Exception {
parent_client = client;
client = new DrillClient(config, serviceSet.getCoordinator());
client = DrillClient.newBuilder()
.setConfig(config)
.setClusterCoordinator(serviceSet.getCoordinator())
.build();
client.setSupportComplexTypes(false);
client.connect();
}
Expand Down
Loading