Skip to content

Commit fb50283

Browse files
DaanHooglandyadvr
authored andcommitted
CID 1302974: Scanner in try-with-resource
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> This closes apache#353 (cherry picked from commit 109b6e9) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent d55d453 commit fb50283

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

  • plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux

‎plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/MemStat.java‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
// under the License.
1717
package org.apache.cloudstack.utils.linux;
1818

19-
import java.util.HashMap;
20-
import java.util.Map;
21-
2219
import java.io.File;
2320
import java.io.FileNotFoundException;
21+
import java.util.HashMap;
22+
import java.util.Map;
2423
import java.util.Scanner;
2524

2625
public class MemStat {
@@ -29,7 +28,7 @@ public class MemStat {
2928
protected final static String CACHE_KEY = "Cached";
3029
protected final static String TOTAL_KEY = "MemTotal";
3130

32-
private Map<String, Double> _memStats = new HashMap<String, Double>();
31+
private final Map<String, Double> _memStats = new HashMap<String, Double>();
3332

3433
public MemStat() {
3534
}
@@ -51,9 +50,9 @@ public Double getCache() {
5150
}
5251

5352
public void refresh() {
54-
try {
55-
Scanner fileScanner = new Scanner(new File(MEMINFO_FILE));
56-
parseFromScanner(fileScanner);
53+
File f = new File(MEMINFO_FILE);
54+
try (Scanner scanner = new Scanner(f)) {
55+
parseFromScanner(scanner);
5756
} catch (FileNotFoundException ex) {
5857
throw new RuntimeException("File " + MEMINFO_FILE + " not found:" + ex.toString());
5958
}

0 commit comments

Comments
 (0)