[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/release] Fix leaking resource in ExitListEntryImpl.java
commit 9fc82fafb32dcc39ebf6780822ecbc06d5f952e5
Author: fava <fava@xxxxxxxxxxxxxxx>
Date: Thu Aug 22 05:41:03 2019 +0000
Fix leaking resource in ExitListEntryImpl.java
Fix leaking resource in ExitListEntryImpl.java using
try-with-resource statement.
This fix is related to analysis on metrics-lib using sonarqube
Implements part of #30544
---
.../descriptor/impl/ExitListEntryImpl.java | 51 +++++++++++-----------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java
index 5389ce3..ba203e2 100644
--- a/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java
@@ -62,31 +62,32 @@ public class ExitListEntryImpl implements ExitList.Entry {
}
private void parseExitListEntry()
- throws DescriptorParseException {
- Scanner scanner = new Scanner(this.exitListEntryString)
- .useDelimiter(ExitList.EOL);
- while (scanner.hasNext()) {
- String line = scanner.next();
- String[] parts = line.split(" ");
- String keyword = parts[0];
- switch (keyword) {
- case "ExitNode":
- this.parseExitNodeLine(line, parts);
- break;
- case "Published":
- this.parsePublishedLine(line, parts);
- break;
- case "LastStatus":
- this.parseLastStatusLine(line, parts);
- break;
- case "ExitAddress":
- this.parseExitAddressLine(line, parts);
- break;
- default:
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
- }
- this.unrecognizedLines.add(line);
+ throws DescriptorParseException {
+ try (Scanner scanner = new Scanner(this.exitListEntryString)
+ .useDelimiter(ExitList.EOL)) {
+ while (scanner.hasNext()) {
+ String line = scanner.next();
+ String[] parts = line.split(" ");
+ String keyword = parts[0];
+ switch (keyword) {
+ case "ExitNode":
+ this.parseExitNodeLine(line, parts);
+ break;
+ case "Published":
+ this.parsePublishedLine(line, parts);
+ break;
+ case "LastStatus":
+ this.parseLastStatusLine(line, parts);
+ break;
+ case "ExitAddress":
+ this.parseExitAddressLine(line, parts);
+ break;
+ default:
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
+ }
}
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits