flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ches...@apache.org
Subject [4/4] flink git commit: [FLINK-4607] Close FileInputStream in ParameterTool and other
Date Fri, 16 Sep 2016 10:35:27 GMT
[FLINK-4607] Close FileInputStream in ParameterTool and other

This closes #2488.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/db90580f
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/db90580f
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/db90580f

Branch: refs/heads/master
Commit: db90580ffdb93a55a6318b18b5d50ec3666b001b
Parents: 9046374
Author: Alexander Pivovarov <apivovarov@gmail.com>
Authored: Fri Sep 9 20:32:28 2016 -0700
Committer: zentol <chesnay@apache.org>
Committed: Fri Sep 16 12:34:45 2016 +0200

----------------------------------------------------------------------
 .../apache/flink/core/fs/local/LocalFileSystemTest.java |  6 +++---
 .../org/apache/flink/api/java/utils/ParameterTool.java  |  6 +++---
 .../apache/flink/api/java/utils/ParameterToolTest.java  |  4 +++-
 .../flink/runtime/util/JarFileCreatorLambdaTest.java    | 12 ++++++------
 .../apache/flink/runtime/util/JarFileCreatorTest.java   | 12 ++++++------
 5 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/db90580f/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
index 299524d..d21e0f1 100644
--- a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
+++ b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
@@ -116,10 +116,10 @@ public class LocalFileSystemTest {
 
 			assertEquals(testfile1.length(), 5L);
 
-			final FileInputStream fisfile1 = new FileInputStream(testfile1);
 			byte[] testbytestest = new byte[5];
-			assertEquals(testbytestest.length, fisfile1.read(testbytestest));
-			fisfile1.close();
+			try (FileInputStream fisfile1 = new FileInputStream(testfile1)) {
+				assertEquals(testbytestest.length, fisfile1.read(testbytestest));
+			}
 			
 			assertArrayEquals(testbytes, testbytestest);
 

http://git-wip-us.apache.org/repos/asf/flink/blob/db90580f/flink-java/src/main/java/org/apache/flink/api/java/utils/ParameterTool.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/utils/ParameterTool.java b/flink-java/src/main/java/org/apache/flink/api/java/utils/ParameterTool.java
index 38ae6df..a9389a5 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/utils/ParameterTool.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/utils/ParameterTool.java
@@ -156,9 +156,9 @@ public class ParameterTool extends ExecutionConfig.GlobalJobParameters
implement
 			throw new FileNotFoundException("Properties file " + propertiesFile.getAbsolutePath()
+ " does not exist");
 		}
 		Properties props = new Properties();
-		FileInputStream fis = new FileInputStream(propertiesFile);
-		props.load(fis);
-		fis.close();
+		try (FileInputStream fis = new FileInputStream(propertiesFile)) {
+			props.load(fis);
+		}
 		return fromMap((Map)props);
 	}
 

http://git-wip-us.apache.org/repos/asf/flink/blob/db90580f/flink-java/src/test/java/org/apache/flink/api/java/utils/ParameterToolTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/utils/ParameterToolTest.java
b/flink-java/src/test/java/org/apache/flink/api/java/utils/ParameterToolTest.java
index 09a7781..605f033 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/utils/ParameterToolTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/utils/ParameterToolTest.java
@@ -185,7 +185,9 @@ public class ParameterToolTest {
 			String pathToFile = tmp.newFile().getAbsolutePath();
 			parameter.createPropertiesFile(pathToFile);
 			Properties defaultProps = new Properties();
-			defaultProps.load(new FileInputStream(pathToFile));
+			try (FileInputStream fis = new FileInputStream(pathToFile)) {
+				defaultProps.load(fis);
+			}
 
 			Assert.assertEquals("myDefaultValue", defaultProps.get("output"));
 			Assert.assertEquals("-1", defaultProps.get("expectedCount"));

http://git-wip-us.apache.org/repos/asf/flink/blob/db90580f/flink-java8/src/test/java/org/apache/flink/runtime/util/JarFileCreatorLambdaTest.java
----------------------------------------------------------------------
diff --git a/flink-java8/src/test/java/org/apache/flink/runtime/util/JarFileCreatorLambdaTest.java
b/flink-java8/src/test/java/org/apache/flink/runtime/util/JarFileCreatorLambdaTest.java
index 249e082..d90f096 100644
--- a/flink-java8/src/test/java/org/apache/flink/runtime/util/JarFileCreatorLambdaTest.java
+++ b/flink-java8/src/test/java/org/apache/flink/runtime/util/JarFileCreatorLambdaTest.java
@@ -98,13 +98,13 @@ public class JarFileCreatorLambdaTest {
 	}
 
 	public boolean validate(Set<String> expected, File out) throws Exception {
-
-		JarInputStream jis = new JarInputStream(new FileInputStream(out));
-		ZipEntry ze;
 		int count = expected.size();
-		while ((ze = jis.getNextEntry()) != null) {
-			count--;
-			expected.remove(ze.getName());
+		try (JarInputStream jis = new JarInputStream(new FileInputStream(out))) {
+			ZipEntry ze;
+			while ((ze = jis.getNextEntry()) != null) {
+				count--;
+				expected.remove(ze.getName());
+			}
 		}
 		return count == 0 && expected.size() == 0;
 	}

http://git-wip-us.apache.org/repos/asf/flink/blob/db90580f/flink-runtime/src/test/java/org/apache/flink/runtime/util/JarFileCreatorTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/util/JarFileCreatorTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/util/JarFileCreatorTest.java
index ba207ec..8f8016e 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/util/JarFileCreatorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/util/JarFileCreatorTest.java
@@ -205,13 +205,13 @@ public class JarFileCreatorTest {
 	}
 
 	private boolean validate(Set<String> expected, File out) throws IOException {
-
-		JarInputStream jis = new JarInputStream(new FileInputStream(out));
-		ZipEntry ze;
 		int count = expected.size();
-		while ((ze = jis.getNextEntry()) != null) {
-			count--;
-			expected.remove(ze.getName());
+		try (JarInputStream jis = new JarInputStream(new FileInputStream(out))) {
+			ZipEntry ze;
+			while ((ze = jis.getNextEntry()) != null) {
+				count--;
+				expected.remove(ze.getName());
+			}
 		}
 		return count == 0 && expected.size() == 0;
 	}


Mime
View raw message