diff options
author | marco <mw.sunshine@gmx.de> | 2015-10-17 13:48:03 +0200 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-11-23 13:58:14 -0500 |
commit | 1aec17636d8c548257cb307f8cc1e41354e00421 (patch) | |
tree | cbfee928075a8ffa5adfcb237d44eccb2f7dd0d0 /src/main/java/com/gitblit | |
parent | 66e081e2dcbca1524003a728d11e7f5ccbdb7bf1 (diff) | |
download | gitblit-1aec17636d8c548257cb307f8cc1e41354e00421.tar.gz gitblit-1aec17636d8c548257cb307f8cc1e41354e00421.zip |
Fix 2 possible NullPointer occurences
Diffstat (limited to 'src/main/java/com/gitblit')
-rw-r--r-- | src/main/java/com/gitblit/manager/FederationManager.java | 4 | ||||
-rw-r--r-- | src/main/java/com/gitblit/utils/FileUtils.java | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/manager/FederationManager.java b/src/main/java/com/gitblit/manager/FederationManager.java index f009c1c8..8f68733b 100644 --- a/src/main/java/com/gitblit/manager/FederationManager.java +++ b/src/main/java/com/gitblit/manager/FederationManager.java @@ -367,6 +367,10 @@ public class FederationManager implements IFederationManager { && file.getName().toLowerCase().endsWith(Constants.PROPOSAL_EXT); } }); + if (files == null) { + return list; + } + for (File file : files) { String json = com.gitblit.utils.FileUtils.readContent(file, null); FederationProposal proposal = JsonUtils.fromJsonString(json, diff --git a/src/main/java/com/gitblit/utils/FileUtils.java b/src/main/java/com/gitblit/utils/FileUtils.java index e7f01045..ad2509d0 100644 --- a/src/main/java/com/gitblit/utils/FileUtils.java +++ b/src/main/java/com/gitblit/utils/FileUtils.java @@ -140,9 +140,10 @@ public class FileUtils { public static String readContent(File file, String lineEnding) {
StringBuilder sb = new StringBuilder();
InputStreamReader is = null;
+ BufferedReader reader = null;
try {
is = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
- BufferedReader reader = new BufferedReader(is);
+ reader = new BufferedReader(is);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
@@ -154,6 +155,14 @@ public class FileUtils { System.err.println("Failed to read content of " + file.getAbsolutePath());
t.printStackTrace();
} finally {
+ if (reader != null){
+ try {
+ reader.close();
+ } catch (IOException ioe) {
+ System.err.println("Failed to close file " + file.getAbsolutePath());
+ ioe.printStackTrace();
+ }
+ }
if (is != null) {
try {
is.close();
|