Skip to content

Commit fceea4b

Browse files
author
Dmitriy Fingerman
committed
code review Oct 15.
1 parent e57209a commit fceea4b

File tree

1 file changed

+8
-9
lines changed
  • iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr

1 file changed

+8
-9
lines changed

iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
package org.apache.iceberg.mr;
2121

22+
import java.io.Closeable;
2223
import java.util.Map;
2324
import java.util.Optional;
2425
import java.util.Properties;
2526
import java.util.Set;
27+
28+
import org.apache.commons.io.IOUtils;
2629
import org.apache.hadoop.conf.Configuration;
2730
import org.apache.iceberg.CatalogUtil;
2831
import org.apache.iceberg.PartitionSpec;
@@ -111,16 +114,12 @@ private static Table loadTable(Configuration conf, String tableIdentifier, Strin
111114

112115
if (catalog.isPresent()) {
113116
Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
114-
115-
if (catalog.get() instanceof AutoCloseable) {
116-
try (AutoCloseable ignored = (AutoCloseable) catalog.get()) {
117-
return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
118-
} catch (Exception e) {
119-
throw new RuntimeException("Failed to close catalog", e);
120-
}
121-
} else {
122-
// fallback if not AutoCloseable
117+
try {
123118
return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
119+
} finally {
120+
if (catalog.get() instanceof Closeable closeable) {
121+
IOUtils.closeQuietly(closeable);
122+
}
124123
}
125124
}
126125

0 commit comments

Comments
 (0)