Skip to content

Commit 1aec176

Browse files
mawulfgitblit
authored andcommitted
Fix 2 possible NullPointer occurences
1 parent 66e081e commit 1aec176

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/com/gitblit/manager/FederationManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ public boolean accept(File file) {
367367
&& file.getName().toLowerCase().endsWith(Constants.PROPOSAL_EXT);
368368
}
369369
});
370+
if (files == null) {
371+
return list;
372+
}
373+
370374
for (File file : files) {
371375
String json = com.gitblit.utils.FileUtils.readContent(file, null);
372376
FederationProposal proposal = JsonUtils.fromJsonString(json,

src/main/java/com/gitblit/utils/FileUtils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ public static long convertSizeToLong(String aString, long defaultValue) {
140140
public static String readContent(File file, String lineEnding) {
141141
StringBuilder sb = new StringBuilder();
142142
InputStreamReader is = null;
143+
BufferedReader reader = null;
143144
try {
144145
is = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
145-
BufferedReader reader = new BufferedReader(is);
146+
reader = new BufferedReader(is);
146147
String line = null;
147148
while ((line = reader.readLine()) != null) {
148149
sb.append(line);
@@ -154,6 +155,14 @@ public static String readContent(File file, String lineEnding) {
154155
System.err.println("Failed to read content of " + file.getAbsolutePath());
155156
t.printStackTrace();
156157
} finally {
158+
if (reader != null){
159+
try {
160+
reader.close();
161+
} catch (IOException ioe) {
162+
System.err.println("Failed to close file " + file.getAbsolutePath());
163+
ioe.printStackTrace();
164+
}
165+
}
157166
if (is != null) {
158167
try {
159168
is.close();

0 commit comments

Comments
 (0)