Repository: tajo Updated Branches: refs/heads/master 0dcb702a0 -> 4e0a7a33c
TAJO-1967: Replace 'try finally' with 'try' with resources. Closes #852 Signed-off-by: Jihoon Son <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/4e0a7a33 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/4e0a7a33 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/4e0a7a33 Branch: refs/heads/master Commit: 4e0a7a33cb055a77f6a29f1e7520d6344616ec7b Parents: 0dcb702 Author: Dongkyu Hwangbo <[email protected]> Authored: Thu Nov 26 11:18:48 2015 +0900 Committer: Jihoon Son <[email protected]> Committed: Thu Nov 26 11:19:12 2015 +0900 ---------------------------------------------------------------------- CHANGES | 3 ++ .../catalog/store/XMLCatalogSchemaManager.java | 17 ++++----- .../org/apache/tajo/cli/tools/TajoAdmin.java | 4 +-- .../org/apache/tajo/cli/tools/TajoGetConf.java | 4 +-- .../org/apache/tajo/cli/tools/TajoHAAdmin.java | 4 +-- .../org/apache/tajo/HBaseTestClusterUtil.java | 10 ++---- .../java/org/apache/tajo/QueryTestCaseBase.java | 5 +-- .../org/apache/tajo/TajoTestingCluster.java | 10 ++---- .../org/apache/tajo/cli/tsql/TestTajoCli.java | 30 ++++++---------- .../apache/tajo/client/v2/TestTajoClientV2.java | 7 ++-- .../tajo/engine/query/TestHBaseTable.java | 35 +++++++----------- .../tajo/engine/query/TestInsertQuery.java | 8 ++--- .../tajo/engine/query/TestNullValues.java | 38 +++++++------------- .../org/apache/tajo/ha/HdfsServiceTracker.java | 7 ++-- .../java/org/apache/tajo/master/TajoMaster.java | 7 ++-- .../tajo/jdbc/TestTajoDatabaseMetaData.java | 10 ++---- .../function/python/PythonScriptEngine.java | 5 +-- .../java/org/apache/tajo/rpc/TestAsyncRpc.java | 14 +++----- .../org/apache/tajo/rpc/TestBlockingRpc.java | 14 +++----- .../tajo/storage/hbase/HBaseTablespace.java | 36 ++++++------------- .../org/objectweb/asm/optimizer/Shrinker.java | 5 +-- 21 files changed, 85 insertions(+), 188 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 00e515e..b9d73c8 100644 --- a/CHANGES +++ b/CHANGES @@ -120,6 +120,9 @@ Release 0.12.0 - unreleased SUB TASKS + TAJO-1967: Replace 'try finally' with 'try' with resources. + (Contributed by Dongkyu Hwangbo, Committed by jihoon) + TAJO-1947: Change Projection::setNamedExprs and getNamedExprs to set and get List<NamedExpr>. (Contributed by Dongkyu Hwangbo, Committed by hyunsik) http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java index 16553e3..c8b7386 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java @@ -416,28 +416,25 @@ public class XMLCatalogSchemaManager { } URL jarFileURL = new URL(spec.substring(0, seperator)); - JarFile jarFile = new JarFile(jarFileURL.toURI().getPath()); Set<String> filesSet = new HashSet<>(); - - try { + + try (JarFile jarFile = new JarFile(jarFileURL.toURI().getPath())) { Enumeration<JarEntry> entries = jarFile.entries(); - + while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); - + if (entry.isDirectory()) { continue; } - + String entryName = entry.getName(); - + if (entryName.indexOf(schemaPath) > -1 && - filter.accept(null, entryName)) { + filter.accept(null, entryName)) { filesSet.add(entryName); } } - } finally { - jarFile.close(); } if (!filesSet.isEmpty()) { http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java ---------------------------------------------------------------------- diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java index d97b06f..79d96e1 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java @@ -447,12 +447,10 @@ public class TajoAdmin { public static void main(String [] args) throws Exception { TajoConf conf = new TajoConf(); - Writer writer = new PrintWriter(System.out); - try { + try (Writer writer = new PrintWriter(System.out)) { TajoAdmin admin = new TajoAdmin(conf, writer); admin.runCommand(args); } finally { - writer.close(); System.exit(0); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoGetConf.java ---------------------------------------------------------------------- diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoGetConf.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoGetConf.java index 19e8eba..5136775 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoGetConf.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoGetConf.java @@ -143,12 +143,10 @@ public class TajoGetConf { public static void main(String [] args) throws Exception { TajoConf conf = new TajoConf(); - Writer writer = new PrintWriter(System.out); - try { + try (Writer writer = new PrintWriter(System.out)) { TajoGetConf admin = new TajoGetConf(conf, writer); admin.runCommand(args, false); } finally { - writer.close(); System.exit(0); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoHAAdmin.java ---------------------------------------------------------------------- diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoHAAdmin.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoHAAdmin.java index 834b6b1..5ada997 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoHAAdmin.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoHAAdmin.java @@ -195,12 +195,10 @@ public class TajoHAAdmin { public static void main(String [] args) throws Exception { TajoConf conf = new TajoConf(); - Writer writer = new PrintWriter(System.out); - try { + try (Writer writer = new PrintWriter(System.out)) { TajoHAAdmin admin = new TajoHAAdmin(conf, writer); admin.runCommand(args); } finally { - writer.close(); System.exit(0); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-cluster-tests/src/test/java/org/apache/tajo/HBaseTestClusterUtil.java ---------------------------------------------------------------------- diff --git a/tajo-cluster-tests/src/test/java/org/apache/tajo/HBaseTestClusterUtil.java b/tajo-cluster-tests/src/test/java/org/apache/tajo/HBaseTestClusterUtil.java index 52c5aa3..1951661 100644 --- a/tajo-cluster-tests/src/test/java/org/apache/tajo/HBaseTestClusterUtil.java +++ b/tajo-cluster-tests/src/test/java/org/apache/tajo/HBaseTestClusterUtil.java @@ -163,20 +163,14 @@ public class HBaseTestClusterUtil { } public HTableDescriptor getTableDescriptor(String tableName) throws IOException { - HBaseAdmin admin = new HBaseAdmin(conf); - try { + try (HBaseAdmin admin = new HBaseAdmin(conf)) { return admin.getTableDescriptor(Bytes.toBytes(tableName)); - } finally { - admin.close(); } } public void createTable(HTableDescriptor hTableDesc) throws IOException { - HBaseAdmin admin = new HBaseAdmin(conf); - try { + try (HBaseAdmin admin = new HBaseAdmin(conf)) { admin.createTable(hTableDesc); - } finally { - admin.close(); } } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java ---------------------------------------------------------------------- diff --git a/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java b/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java index 0b649fc..eb40562 100644 --- a/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java +++ b/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java @@ -1092,8 +1092,7 @@ public class QueryTestCaseBase { continue; } - InputStream in = fs.open(file.getPath()); - try { + try (InputStream in = fs.open(file.getPath())) { while (true) { int readBytes = in.read(buf); if (readBytes <= 0) { @@ -1102,8 +1101,6 @@ public class QueryTestCaseBase { sb.append(new String(buf, 0, readBytes)); } - } finally { - in.close(); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-cluster-tests/src/test/java/org/apache/tajo/TajoTestingCluster.java ---------------------------------------------------------------------- diff --git a/tajo-cluster-tests/src/test/java/org/apache/tajo/TajoTestingCluster.java b/tajo-cluster-tests/src/test/java/org/apache/tajo/TajoTestingCluster.java index 9e0e060..3dfb902 100644 --- a/tajo-cluster-tests/src/test/java/org/apache/tajo/TajoTestingCluster.java +++ b/tajo-cluster-tests/src/test/java/org/apache/tajo/TajoTestingCluster.java @@ -631,12 +631,9 @@ public class TajoTestingCluster { Thread.sleep(1000); } TajoConf conf = util.getConfiguration(); - TajoClient client = new TajoClientImpl(ServiceTrackerFactory.get(conf)); - try { + try (TajoClient client = new TajoClientImpl(ServiceTrackerFactory.get(conf))) { return run(names, schemas, tableOption, tables, query, client); - } finally { - client.close(); } } @@ -660,8 +657,7 @@ public class TajoTestingCluster { KeyValueSet tableOption, String[] tableDatas, int numDataFiles) throws Exception { TpchTestBase instance = TpchTestBase.getInstance(); TajoTestingCluster util = instance.getTestingCluster(); - TajoClient client = newTajoClient(util); - try { + try (TajoClient client = newTajoClient(util)) { FileSystem fs = util.getDefaultFileSystem(); Path rootDir = TajoConf.getWarehouseDir(util.getConfiguration()); if (!fs.exists(rootDir)) { @@ -698,8 +694,6 @@ public class TajoTestingCluster { } TableMeta meta = CatalogUtil.newTableMeta("TEXT", tableOption); client.createExternalTable(tableName, schema, tablePath.toUri(), meta); - } finally { - client.close(); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java index 886c280..d603f4a 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java @@ -164,12 +164,9 @@ public class TestTajoCli { assertEquals("tajo.executor.join.inner.in-memory-table-num=256", confValues[1]); TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration(); - TajoCli testCli = new TajoCli(tajoConf, args, null, System.in, System.out); - try { + try (TajoCli testCli = new TajoCli(tajoConf, args, null, System.in, System.out)) { assertEquals("false", testCli.getContext().get(SessionVars.CLI_PAGING_ENABLED)); assertEquals("256", testCli.getContext().getConf().get("tajo.executor.join.inner.in-memory-table-num")); - } finally { - testCli.close(); } } @@ -346,16 +343,13 @@ public class TestTajoCli { public void testGetConf() throws Exception { TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration(); setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - TajoCli tajoCli = new TajoCli(tajoConf, new String[]{}, null, System.in, out); - try { + + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); + TajoCli tajoCli = new TajoCli(tajoConf, new String[]{}, null, System.in, out)) { tajoCli.executeMetaCommand("\\getconf tajo.rootdir"); String consoleResult = new String(out.toByteArray()); assertEquals(consoleResult, tajoCli.getContext().getConf().getVar(TajoConf.ConfVars.ROOT_DIR) + "\n"); - } finally { - tajoCli.close(); } } @@ -474,14 +468,12 @@ public class TestTajoCli { @Test(timeout = 3000) public void testNonForwardQueryPause() throws Exception { final String sql = "select * from default.lineitem"; - TajoCli cli = null; - try { - TableDesc tableDesc = cluster.getMaster().getCatalog().getTableDesc("default", "lineitem"); - assertNotNull(tableDesc); - assertEquals(0L, tableDesc.getStats().getNumRows().longValue()); - - InputStream testInput = new ByteArrayInputStream(new byte[]{(byte) DefaultTajoCliOutputFormatter.QUIT_COMMAND}); - cli = new TajoCli(cluster.getConfiguration(), new String[]{}, null, testInput, out); + TableDesc tableDesc = cluster.getMaster().getCatalog().getTableDesc("default", "lineitem"); + assertNotNull(tableDesc); + assertEquals(0L, tableDesc.getStats().getNumRows().longValue()); + + try (InputStream testInput = new ByteArrayInputStream(new byte[]{(byte) DefaultTajoCliOutputFormatter.QUIT_COMMAND}); + TajoCli cli = new TajoCli(cluster.getConfiguration(), new String[]{}, null, testInput, out)) { setVar(cli, SessionVars.CLI_PAGE_ROWS, "2"); setVar(cli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); @@ -490,8 +482,6 @@ public class TestTajoCli { String consoleResult; consoleResult = new String(out.toByteArray()); assertOutputResult(consoleResult); - } finally { - cli.close(); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-core-tests/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java b/tajo-core-tests/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java index fba8b42..f6b4f88 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java @@ -264,14 +264,11 @@ public class TestTajoClientV2 extends QueryTestCaseBase { @Test(expected = QueryFailedException.class) public void testFailedExecuteQueryAsync() throws Throwable { - QueryFuture future = clientv2.executeQueryAsync( - "select fail(3, l_orderkey, 'testQueryFailure') from default.lineitem where l_orderkey > 0"); - try { + try (QueryFuture future = clientv2.executeQueryAsync( + "select fail(3, l_orderkey, 'testQueryFailure') from default.lineitem where l_orderkey > 0")) { future.get(); } catch (ExecutionException e) { throw e.getCause(); - } finally { - future.close(); } } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestHBaseTable.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestHBaseTable.java b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestHBaseTable.java index 395b981..95109b9 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestHBaseTable.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestHBaseTable.java @@ -139,11 +139,8 @@ public class TestHBaseTable extends QueryTestCaseBase { executeString("DROP TABLE hbase_mapped_table1 PURGE").close(); - HBaseAdmin hAdmin = new HBaseAdmin(testingCluster.getHBaseUtil().getConf()); - try { + try (HBaseAdmin hAdmin = new HBaseAdmin(testingCluster.getHBaseUtil().getConf())) { assertFalse(hAdmin.tableExists("hbase_table")); - } finally { - hAdmin.close(); } } @@ -202,13 +199,10 @@ public class TestHBaseTable extends QueryTestCaseBase { executeString("DROP TABLE external_hbase_mapped_table").close(); - HBaseAdmin hAdmin = new HBaseAdmin(testingCluster.getHBaseUtil().getConf()); - try { + try (HBaseAdmin hAdmin = new HBaseAdmin(testingCluster.getHBaseUtil().getConf())) { assertTrue(hAdmin.tableExists("external_hbase_table_not_purge")); hAdmin.disableTable("external_hbase_table_not_purge"); hAdmin.deleteTable("external_hbase_table_not_purge"); - } finally { - hAdmin.close(); } } finally { @@ -238,9 +232,8 @@ public class TestHBaseTable extends QueryTestCaseBase { assertTableExists("external_hbase_mapped_table"); HConnection hconn = ((HBaseTablespace)existing.get()).getConnection(); - HTableInterface htable = hconn.getTable("external_hbase_table"); - try { + try (HTableInterface htable = hconn.getTable("external_hbase_table")) { for (int i = 0; i < 100; i++) { Put put = new Put(String.valueOf(i).getBytes()); put.add("col1".getBytes(), "a".getBytes(), ("a-" + i).getBytes()); @@ -256,7 +249,7 @@ public class TestHBaseTable extends QueryTestCaseBase { cleanupQuery(res); } finally { executeString("DROP TABLE external_hbase_mapped_table PURGE").close(); - htable.close(); + } } finally { TablespaceManager.addTableSpaceForTest(existing.get()); @@ -284,9 +277,8 @@ public class TestHBaseTable extends QueryTestCaseBase { assertTableExists("external_hbase_mapped_table"); HConnection hconn = ((HBaseTablespace)existing.get()).getConnection(); - HTableInterface htable = hconn.getTable("external_hbase_table"); - try { + try (HTableInterface htable = hconn.getTable("external_hbase_table")) { for (int i = 0; i < 100; i++) { Put put = new Put(Bytes.toBytes((long) i)); put.add("col1".getBytes(), "a".getBytes(), ("a-" + i).getBytes()); @@ -316,7 +308,7 @@ public class TestHBaseTable extends QueryTestCaseBase { } finally { executeString("DROP TABLE external_hbase_mapped_table PURGE").close(); - htable.close(); + } } finally { TablespaceManager.addTableSpaceForTest(existing.get()); @@ -343,9 +335,8 @@ public class TestHBaseTable extends QueryTestCaseBase { assertTableExists("external_hbase_mapped_table"); HConnection hconn = ((HBaseTablespace)existing.get()).getConnection(); - HTableInterface htable = hconn.getTable("external_hbase_table"); - try { + try (HTableInterface htable = hconn.getTable("external_hbase_table")) { for (int i = 0; i < 10; i++) { Put put = new Put(Bytes.toBytes("rk-" + i)); for (int j = 0; j < 5; j++) { @@ -360,7 +351,7 @@ public class TestHBaseTable extends QueryTestCaseBase { cleanupQuery(res); } finally { executeString("DROP TABLE external_hbase_mapped_table PURGE").close(); - htable.close(); + } } finally { TablespaceManager.addTableSpaceForTest(existing.get()); @@ -387,9 +378,8 @@ public class TestHBaseTable extends QueryTestCaseBase { HConnection hconn = ((HBaseTablespace)existing.get()).getConnection(); - HTableInterface htable = hconn.getTable("external_hbase_table"); - try { + try (HTableInterface htable = hconn.getTable("external_hbase_table")) { for (int i = 0; i < 100; i++) { Put put = new Put(("field1-" + i + "_field2-" + i).getBytes()); put.add("col3".getBytes(), "a".getBytes(), ("a-" + i).getBytes()); @@ -401,7 +391,7 @@ public class TestHBaseTable extends QueryTestCaseBase { cleanupQuery(res); } finally { executeString("DROP TABLE external_hbase_mapped_table PURGE").close(); - htable.close(); + } } finally { TablespaceManager.addTableSpaceForTest(existing.get()); @@ -616,9 +606,8 @@ public class TestHBaseTable extends QueryTestCaseBase { "'hbase.split.rowkeys'='010,040,060,080')").close(); assertTableExists("hbase_mapped_table1"); - HBaseAdmin hAdmin = new HBaseAdmin(testingCluster.getHBaseUtil().getConf()); HTable htable = null; - try { + try (HBaseAdmin hAdmin = new HBaseAdmin(testingCluster.getHBaseUtil().getConf())) { hAdmin.tableExists("hbase_table1"); htable = new HTable(testingCluster.getHBaseUtil().getConf(), "hbase_table1"); org.apache.hadoop.hbase.util.Pair<byte[][], byte[][]> keys = htable.getStartEndKeys(); @@ -640,7 +629,7 @@ public class TestHBaseTable extends QueryTestCaseBase { res.close(); } finally { executeString("DROP TABLE hbase_mapped_table1 PURGE").close(); - hAdmin.close(); + if (htable == null) { htable.close(); } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java index 328eda5..05c30df 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java @@ -726,10 +726,8 @@ public class TestInsertQuery extends QueryTestCaseBase { CompressionCodec codec = factory.getCodec(file.getPath()); assertTrue(codec instanceof DeflateCodec); - BufferedReader reader = new BufferedReader( - new InputStreamReader(codec.createInputStream(fs.open(file.getPath())))); - - try { + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(codec.createInputStream(fs.open(file.getPath()))))) { String line = reader.readLine(); assertNotNull(line); @@ -739,8 +737,6 @@ public class TestInsertQuery extends QueryTestCaseBase { assertEquals("1", tokens[0]); assertEquals("2.1", tokens[1]); assertEquals("test", tokens[2]); - } finally { - reader.close(); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestNullValues.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestNullValues.java b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestNullValues.java index 66848e6..791a819 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestNullValues.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestNullValues.java @@ -70,16 +70,13 @@ public class TestNullValues { }; KeyValueSet opts = new KeyValueSet(); opts.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER); - ResultSet res = TajoTestingCluster - .run(table, schemas, opts, new String[][]{data}, - "select * from nulltable1 where col3 is null", client); - try { + try (ResultSet res = TajoTestingCluster + .run(table, schemas, opts, new String[][]{data}, + "select * from nulltable1 where col3 is null", client)) { assertTrue(res.next()); assertEquals(2, res.getInt(1)); assertFalse(res.next()); - } finally { - res.close(); } } @@ -97,17 +94,14 @@ public class TestNullValues { }; KeyValueSet opts = new KeyValueSet(); opts.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER); - ResultSet res = TajoTestingCluster - .run(table, schemas, opts, new String[][]{data}, - "select * from nulltable2 where col1 is not null", client); - try { + try (ResultSet res = TajoTestingCluster + .run(table, schemas, opts, new String[][]{data}, + "select * from nulltable2 where col1 is not null", client)) { assertTrue(res.next()); assertEquals(1, res.getInt(1)); assertTrue(res.next()); assertEquals(3, res.getInt(1)); assertFalse(res.next()); - } finally { - res.close(); } } @@ -132,15 +126,12 @@ public class TestNullValues { }; KeyValueSet opts = new KeyValueSet(); opts.set(StorageConstants.TEXT_DELIMITER, ","); - ResultSet res = TajoTestingCluster - .run(table, schemas, opts, new String[][]{data}, - "select * from nulltable3 where col1 is null and col2 is null and col3 is null and col4 = 43578", client); - try { + try (ResultSet res = TajoTestingCluster + .run(table, schemas, opts, new String[][]{data}, + "select * from nulltable3 where col1 is null and col2 is null and col3 is null and col4 = 43578", client)) { assertTrue(res.next()); assertEquals(43578, res.getLong(4)); assertFalse(res.next()); - } finally { - res.close(); } } @@ -166,16 +157,13 @@ public class TestNullValues { KeyValueSet opts = new KeyValueSet(); opts.set(StorageConstants.TEXT_DELIMITER, ","); opts.set(StorageConstants.TEXT_NULL, "\\\\N"); - ResultSet res = TajoTestingCluster - .run(table, schemas, opts, new String[][]{data}, - "select * from nulltable4 where col1 is null and col2 is null and col3 is null and col5 is null and col4 = 43578" - , client); - try { + try (ResultSet res = TajoTestingCluster + .run(table, schemas, opts, new String[][]{data}, + "select * from nulltable4 where col1 is null and col2 is null and col3 is null and col5 is null and col4 = 43578" + , client)) { assertTrue(res.next()); assertEquals(43578, res.getLong(4)); assertFalse(res.next()); - } finally { - res.close(); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-core/src/main/java/org/apache/tajo/ha/HdfsServiceTracker.java ---------------------------------------------------------------------- diff --git a/tajo-core/src/main/java/org/apache/tajo/ha/HdfsServiceTracker.java b/tajo-core/src/main/java/org/apache/tajo/ha/HdfsServiceTracker.java index e7f4748..4c7732f 100644 --- a/tajo-core/src/main/java/org/apache/tajo/ha/HdfsServiceTracker.java +++ b/tajo-core/src/main/java/org/apache/tajo/ha/HdfsServiceTracker.java @@ -203,12 +203,9 @@ public class HdfsServiceTracker extends HAServiceTracker { private void writeSystemConf() throws IOException { Path systemConfPath = TajoConf.getSystemConfPath(conf); - FSDataOutputStream out = FileSystem.create(fs, systemConfPath, - new FsPermission(TajoMaster.SYSTEM_CONF_FILE_PERMISSION)); - try { + try (FSDataOutputStream out = FileSystem.create(fs, systemConfPath, + new FsPermission(TajoMaster.SYSTEM_CONF_FILE_PERMISSION))) { conf.writeXml(out); - } finally { - out.close(); } fs.setReplication(systemConfPath, (short) conf.getIntVar(ConfVars.SYSTEM_CONF_REPLICA_COUNT)); } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java ---------------------------------------------------------------------- diff --git a/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java b/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java index 12175ee..a8a84fe 100644 --- a/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java +++ b/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java @@ -362,12 +362,9 @@ public class TajoMaster extends CompositeService { // In TajoMaster HA, some master might see LeaseExpiredException because of lease mismatch. Thus, // we need to create below xml file at HdfsServiceTracker::writeSystemConf. if (!systemConf.getBoolVar(TajoConf.ConfVars.TAJO_MASTER_HA_ENABLE)) { - FSDataOutputStream out = FileSystem.create(defaultFS, systemConfPath, - new FsPermission(SYSTEM_CONF_FILE_PERMISSION)); - try { + try (FSDataOutputStream out = FileSystem.create(defaultFS, systemConfPath, + new FsPermission(SYSTEM_CONF_FILE_PERMISSION))) { systemConf.writeXml(out); - } finally { - out.close(); } defaultFS.setReplication(systemConfPath, (short) systemConf.getIntVar(ConfVars.SYSTEM_CONF_REPLICA_COUNT)); } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-jdbc/src/test/java/org/apache/tajo/jdbc/TestTajoDatabaseMetaData.java ---------------------------------------------------------------------- diff --git a/tajo-jdbc/src/test/java/org/apache/tajo/jdbc/TestTajoDatabaseMetaData.java b/tajo-jdbc/src/test/java/org/apache/tajo/jdbc/TestTajoDatabaseMetaData.java index 3107af9..1b694c0 100644 --- a/tajo-jdbc/src/test/java/org/apache/tajo/jdbc/TestTajoDatabaseMetaData.java +++ b/tajo-jdbc/src/test/java/org/apache/tajo/jdbc/TestTajoDatabaseMetaData.java @@ -400,9 +400,8 @@ public class TestTajoDatabaseMetaData extends QueryTestCaseBase { if (!testingCluster.isHiveCatalogStoreRunning()) { String connUri = TestTajoJdbc.buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), TajoConstants.DEFAULT_DATABASE_NAME); - Connection conn = DriverManager.getConnection(connUri); - try { + try (Connection conn = DriverManager.getConnection(connUri)) { DatabaseMetaData meta = conn.getMetaData(); ResultSet res = meta.getProcedures(null, null, null); @@ -456,8 +455,6 @@ public class TestTajoDatabaseMetaData extends QueryTestCaseBase { res = meta.getClientInfoProperties(); assertNotNull(res); assertFalse(res.next()); - } finally { - conn.close(); } } } @@ -467,9 +464,8 @@ public class TestTajoDatabaseMetaData extends QueryTestCaseBase { if (!testingCluster.isHiveCatalogStoreRunning()) { String connUri = TestTajoJdbc.buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), TajoConstants.DEFAULT_DATABASE_NAME); - Connection conn = DriverManager.getConnection(connUri); - try { + try (Connection conn = DriverManager.getConnection(connUri)) { DatabaseMetaData meta = conn.getMetaData(); ResultSet res = meta.getTypeInfo(); @@ -496,8 +492,6 @@ public class TestTajoDatabaseMetaData extends QueryTestCaseBase { } assertEquals(numTypes, TajoTypeUtil.getTypeInfos().size()); - } finally { - conn.close(); } } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-plan/src/main/java/org/apache/tajo/plan/function/python/PythonScriptEngine.java ---------------------------------------------------------------------- diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/python/PythonScriptEngine.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/python/PythonScriptEngine.java index 419ad67..19a4ac2 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/python/PythonScriptEngine.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/python/PythonScriptEngine.java @@ -75,12 +75,9 @@ public class PythonScriptEngine extends TajoScriptEngine { Set<FunctionDesc> functionDescs = new HashSet<>(); - InputStream in = getScriptAsStream(path); List<FunctionInfo> functions = null; - try { + try (InputStream in = getScriptAsStream(path)) { functions = getFunctions(in); - } finally { - in.close(); } for(FunctionInfo funcInfo : functions) { http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestAsyncRpc.java ---------------------------------------------------------------------- diff --git a/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestAsyncRpc.java b/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestAsyncRpc.java index 1acfe40..404e1b6 100644 --- a/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestAsyncRpc.java +++ b/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestAsyncRpc.java @@ -421,23 +421,19 @@ public class TestAsyncRpc { public void testUnresolvedAddress() throws Exception { InetSocketAddress address = new InetSocketAddress("test", 0); boolean expected = false; - AsyncRpcClient client = null; - try { - RpcConnectionKey rpcConnectionKey = - new RpcConnectionKey(address, DummyProtocol.class, true); + RpcConnectionKey rpcConnectionKey = + new RpcConnectionKey(address, DummyProtocol.class, true); - Properties connParams = new Properties(); - connParams.setProperty(RpcConstants.CLIENT_RETRY_NUM, String.valueOf(retries)); + Properties connParams = new Properties(); + connParams.setProperty(RpcConstants.CLIENT_RETRY_NUM, String.valueOf(retries)); - client = new AsyncRpcClient(NettyUtils.getDefaultEventLoopGroup(), rpcConnectionKey, connParams); + try (AsyncRpcClient client = new AsyncRpcClient(NettyUtils.getDefaultEventLoopGroup(), rpcConnectionKey, connParams)) { client.connect(); fail(); } catch (ConnectException e) { expected = true; } catch (Throwable throwable) { fail(throwable.getMessage()); - } finally { - client.close(); } assertTrue(expected); http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestBlockingRpc.java ---------------------------------------------------------------------- diff --git a/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestBlockingRpc.java b/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestBlockingRpc.java index 08ab887..62696e1 100644 --- a/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestBlockingRpc.java +++ b/tajo-rpc/tajo-rpc-protobuf/src/test/java/org/apache/tajo/rpc/TestBlockingRpc.java @@ -378,23 +378,19 @@ public class TestBlockingRpc { public void testUnresolvedAddress() throws Exception { InetSocketAddress address = new InetSocketAddress("test", 0); boolean expected = false; - BlockingRpcClient client = null; - try { - RpcConnectionKey rpcConnectionKey = - new RpcConnectionKey(address, DummyProtocol.class, true); + RpcConnectionKey rpcConnectionKey = + new RpcConnectionKey(address, DummyProtocol.class, true); - Properties connParams = new Properties(); - connParams.setProperty(RpcConstants.CLIENT_RETRY_NUM, retries + ""); + Properties connParams = new Properties(); + connParams.setProperty(RpcConstants.CLIENT_RETRY_NUM, retries + ""); - client = new BlockingRpcClient(NettyUtils.getDefaultEventLoopGroup(), rpcConnectionKey, connParams); + try (BlockingRpcClient client = new BlockingRpcClient(NettyUtils.getDefaultEventLoopGroup(), rpcConnectionKey, connParams)) { client.connect(); fail(); } catch (ConnectException e) { expected = true; } catch (Throwable throwable) { fail(throwable.getMessage()); - } finally { - client.close(); } assertTrue(expected); } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-storage/tajo-storage-hbase/src/main/java/org/apache/tajo/storage/hbase/HBaseTablespace.java ---------------------------------------------------------------------- diff --git a/tajo-storage/tajo-storage-hbase/src/main/java/org/apache/tajo/storage/hbase/HBaseTablespace.java b/tajo-storage/tajo-storage-hbase/src/main/java/org/apache/tajo/storage/hbase/HBaseTablespace.java index 7ace9a8..f06cc67 100644 --- a/tajo-storage/tajo-storage-hbase/src/main/java/org/apache/tajo/storage/hbase/HBaseTablespace.java +++ b/tajo-storage/tajo-storage-hbase/src/main/java/org/apache/tajo/storage/hbase/HBaseTablespace.java @@ -161,9 +161,7 @@ public class HBaseTablespace extends Tablespace { } } - HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf()); - - try { + try (HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf())) { if (isExternal) { // If tajo table is external table, only check validation. if (mappedColumns == null || mappedColumns.isEmpty()) { @@ -178,7 +176,7 @@ public class HBaseTablespace extends Tablespace { tableColumnFamilies.add(eachColumn.getNameAsString()); } - Collection<String> mappingColumnFamilies =columnMapping.getColumnFamilyNames(); + Collection<String> mappingColumnFamilies = columnMapping.getColumnFamilyNames(); if (mappingColumnFamilies.isEmpty()) { throw new MissingTablePropertyException(HBaseStorageConstants.META_COLUMNS_KEY, hbaseTableName); } @@ -206,8 +204,6 @@ public class HBaseTablespace extends Tablespace { hAdmin.createTable(hTableDescriptor, splitKeys); } } - } finally { - hAdmin.close(); } } @@ -370,15 +366,12 @@ public class HBaseTablespace extends Tablespace { @Override public void purgeTable(TableDesc tableDesc) throws IOException, TajoException { - HBaseAdmin hAdmin = new HBaseAdmin(hbaseConf); - try { + try (HBaseAdmin hAdmin = new HBaseAdmin(hbaseConf)) { HTableDescriptor hTableDesc = parseHTableDescriptor(tableDesc.getMeta(), tableDesc.getSchema()); LOG.info("Deleting hbase table: " + new String(hTableDesc.getName())); hAdmin.disableTable(hTableDesc.getName()); hAdmin.deleteTable(hTableDesc.getName()); - } finally { - hAdmin.close(); } } @@ -917,8 +910,7 @@ public class HBaseTablespace extends Tablespace { // insert into table String tableName = tableDesc.getMeta().getProperty(HBaseStorageConstants.META_TABLE_KEY); - HTable htable = new HTable(hbaseConf, tableName); - try { + try (HTable htable = new HTable(hbaseConf, tableName)) { LoadIncrementalHFiles loadIncrementalHFiles = null; try { loadIncrementalHFiles = new LoadIncrementalHFiles(hbaseConf); @@ -929,8 +921,6 @@ public class HBaseTablespace extends Tablespace { loadIncrementalHFiles.doBulkLoad(stagingResultDir, htable); return stagingResultDir; - } finally { - htable.close(); } } @@ -946,8 +936,7 @@ public class HBaseTablespace extends Tablespace { ColumnMapping columnMapping = new ColumnMapping(tableDesc.getSchema(), tableDesc.getMeta().getPropertySet()); - HTable htable = new HTable(hbaseConf, columnMapping.getHbaseTableName()); - try { + try (HTable htable = new HTable(hbaseConf, columnMapping.getHbaseTableName())) { byte[][] endKeys = htable.getEndKeys(); if (endKeys.length == 1) { return new TupleRange[]{dataRange}; @@ -984,12 +973,12 @@ public class HBaseTablespace extends Tablespace { for (int i = 0; i < sortSpecs.length; i++) { if (columnMapping.getIsBinaryColumns()[sortKeyIndexes[i]]) { endTuple.put(i, - HBaseBinarySerializerDeserializer.deserialize(inputSchema.getColumn(sortKeyIndexes[i]), - rowKeyFields[i])); + HBaseBinarySerializerDeserializer.deserialize(inputSchema.getColumn(sortKeyIndexes[i]), + rowKeyFields[i])); } else { endTuple.put(i, - HBaseTextSerializerDeserializer.deserialize(inputSchema.getColumn(sortKeyIndexes[i]), - rowKeyFields[i])); + HBaseTextSerializerDeserializer.deserialize(inputSchema.getColumn(sortKeyIndexes[i]), + rowKeyFields[i])); } } tupleRanges.add(new TupleRange(sortSpecs, previousTuple, endTuple)); @@ -1003,8 +992,6 @@ public class HBaseTablespace extends Tablespace { tupleRanges.remove(tupleRanges.size() - 1); } return tupleRanges.toArray(new TupleRange[tupleRanges.size()]); - } finally { - htable.close(); } } catch (Throwable t) { LOG.error(t.getMessage(), t); @@ -1055,15 +1042,12 @@ public class HBaseTablespace extends Tablespace { return; } - HBaseAdmin hAdmin = new HBaseAdmin(this.hbaseConf); TableMeta tableMeta = new TableMeta(cNode.getStorageType(), cNode.getOptions()); - try { + try (HBaseAdmin hAdmin = new HBaseAdmin(this.hbaseConf)) { HTableDescriptor hTableDesc = parseHTableDescriptor(tableMeta, cNode.getTableSchema()); LOG.info("Delete table cause query failed:" + new String(hTableDesc.getName())); hAdmin.disableTable(hTableDesc.getName()); hAdmin.deleteTable(hTableDesc.getName()); - } finally { - hAdmin.close(); } } } http://git-wip-us.apache.org/repos/asf/tajo/blob/4e0a7a33/tajo-thirdparty/asm/src/main/java/org/apache/tajo/org/objectweb/asm/optimizer/Shrinker.java ---------------------------------------------------------------------- diff --git a/tajo-thirdparty/asm/src/main/java/org/apache/tajo/org/objectweb/asm/optimizer/Shrinker.java b/tajo-thirdparty/asm/src/main/java/org/apache/tajo/org/objectweb/asm/optimizer/Shrinker.java index b02b63f..2ce4c3b 100644 --- a/tajo-thirdparty/asm/src/main/java/org/apache/tajo/org/objectweb/asm/optimizer/Shrinker.java +++ b/tajo-thirdparty/asm/src/main/java/org/apache/tajo/org/objectweb/asm/optimizer/Shrinker.java @@ -134,11 +134,8 @@ public class Shrinker { throw new IOException("Cannot create directory " + g.getParentFile()); } - OutputStream os = new FileOutputStream(g); - try { + try (OutputStream os = new FileOutputStream(g)) { os.write(cw.toByteArray()); - } finally { - os.close(); } } }
