Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
code: Fix NPE when access nonexistent path
Browse files Browse the repository at this point in the history
NPE occured when access a file or a directory that does not exist or
root directory of an empty commit.
  • Loading branch information
Yi EungJun committed Mar 10, 2015
1 parent 7cdea2e commit f739919
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/CodeApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public static Result codeBrowserWithBranch(String userName, String projectName,
List<ObjectNode> recursiveData = RepositoryService.getMetaDataFromAncestorDirectories(
repository, branch, path);

if (recursiveData == null) {
return notFound(ErrorViews.NotFound.render());
}

return ok(view.render(project, branches, recursiveData, branch, path));
}

Expand Down
6 changes: 6 additions & 0 deletions app/playRepository/RepositoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ public static List<ObjectNode> getMetaDataFromAncestorDirectories(PlayRepository
ObjectNode metaData;

metaData = repository.getMetaDataFromPath(branch, "");
if (metaData == null) {
return null;
}
metaData.put("path", "");
recursiveData.add(metaData);
for(int i = 0; i < pathLength; i++){
partialPath = (partialPath.equals("")) ? pathArray[i] : partialPath + "/" + pathArray[i];
if (!repository.isIntermediateFolder(partialPath)) {
metaData = repository.getMetaDataFromPath(branch, partialPath);
if (metaData == null) {
return null;
}
metaData.put("path", partialPath);
recursiveData.add(metaData);
}
Expand Down

0 comments on commit f739919

Please sign in to comment.