Skip to content

Commit d6b7b35

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

File tree

1 file changed

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

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
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+
import org.apache.commons.io.IOUtils;
2628
import org.apache.hadoop.conf.Configuration;
2729
import org.apache.iceberg.CatalogUtil;
2830
import org.apache.iceberg.PartitionSpec;
@@ -111,16 +113,12 @@ private static Table loadTable(Configuration conf, String tableIdentifier, Strin
111113

112114
if (catalog.isPresent()) {
113115
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
116+
try {
123117
return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
118+
} finally {
119+
if (catalog.get() instanceof Closeable closeable) {
120+
IOUtils.closeQuietly(closeable);
121+
}
124122
}
125123
}
126124

0 commit comments

Comments
 (0)