From f73991980949e2989076f20d64fefa89558c0f24 Mon Sep 17 00:00:00 2001 From: Yi EungJun Date: Tue, 10 Mar 2015 15:31:04 +0900 Subject: [PATCH] code: Fix NPE when access nonexistent path NPE occured when access a file or a directory that does not exist or root directory of an empty commit. --- app/controllers/CodeApp.java | 4 ++++ app/playRepository/RepositoryService.java | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/app/controllers/CodeApp.java b/app/controllers/CodeApp.java index 815b41caa..86f5b3f3c 100644 --- a/app/controllers/CodeApp.java +++ b/app/controllers/CodeApp.java @@ -98,6 +98,10 @@ public static Result codeBrowserWithBranch(String userName, String projectName, List recursiveData = RepositoryService.getMetaDataFromAncestorDirectories( repository, branch, path); + if (recursiveData == null) { + return notFound(ErrorViews.NotFound.render()); + } + return ok(view.render(project, branches, recursiveData, branch, path)); } diff --git a/app/playRepository/RepositoryService.java b/app/playRepository/RepositoryService.java index 609d78b8d..420bbcb3a 100644 --- a/app/playRepository/RepositoryService.java +++ b/app/playRepository/RepositoryService.java @@ -86,12 +86,18 @@ public static List 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); }