diff --git a/java/com/google/gerrit/server/restapi/project/GetAccess.java b/java/com/google/gerrit/server/restapi/project/GetAccess.java index 915fd209e2..9e431df1b1 100644 --- a/java/com/google/gerrit/server/restapi/project/GetAccess.java +++ b/java/com/google/gerrit/server/restapi/project/GetAccess.java @@ -156,12 +156,15 @@ public class GetAccess implements RestReadView { config = ProjectConfig.read(md); info.configWebLinks = new ArrayList<>(); - // WebLinks operates in terms of the data types used in the GWT UI. Once the GWT UI is gone, - // WebLinks should be fixed to use the extension data types. - for (WebLinkInfoCommon wl : - webLinks.getFileHistoryLinks( - projectName.get(), config.getRevision().getName(), ProjectConfig.PROJECT_CONFIG)) { - info.configWebLinks.add(new WebLinkInfo(wl.name, wl.imageUrl, wl.url, wl.target)); + // config may have a null revision if the repo doesn't have its own refs/meta/config. + if (config.getRevision() != null) { + // WebLinks operates in terms of the data types used in the GWT UI. Once the GWT UI is + // gone, WebLinks should be fixed to use the extension data types. + for (WebLinkInfoCommon wl : + webLinks.getFileHistoryLinks( + projectName.get(), config.getRevision().getName(), ProjectConfig.PROJECT_CONFIG)) { + info.configWebLinks.add(new WebLinkInfo(wl.name, wl.imageUrl, wl.url, wl.target)); + } } if (config.updateGroupNames(groupBackend)) { diff --git a/javatests/com/google/gerrit/acceptance/rest/project/AccessIT.java b/javatests/com/google/gerrit/acceptance/rest/project/AccessIT.java index 44b10a1b2d..532ce4513d 100644 --- a/javatests/com/google/gerrit/acceptance/rest/project/AccessIT.java +++ b/javatests/com/google/gerrit/acceptance/rest/project/AccessIT.java @@ -52,6 +52,9 @@ import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.RefUpdate; +import org.eclipse.jgit.lib.RefUpdate.Result; +import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; import org.junit.Test; @@ -83,17 +86,15 @@ public class AccessIT extends AbstractDaemonTest { } @Test - public void webLinks() throws Exception { + public void webLink() throws Exception { RegistrationHandle handle = fileHistoryWebLinkDynamicSet.add( new FileHistoryWebLink() { @Override public WebLinkInfo getFileHistoryWebLink( String projectName, String revision, String fileName) { - WebLinkInfo info = - new WebLinkInfo( - "name", "imageURL", "http://view/" + projectName + "/" + fileName); - return info; + return new WebLinkInfo( + "name", "imageURL", "http://view/" + projectName + "/" + fileName); } }); try { @@ -106,6 +107,30 @@ public class AccessIT extends AbstractDaemonTest { } } + @Test + public void webLinkNoRefsMetaConfig() throws Exception { + RegistrationHandle handle = + fileHistoryWebLinkDynamicSet.add( + new FileHistoryWebLink() { + @Override + public WebLinkInfo getFileHistoryWebLink( + String projectName, String revision, String fileName) { + return new WebLinkInfo( + "name", "imageURL", "http://view/" + projectName + "/" + fileName); + } + }); + try (Repository repo = repoManager.openRepository(new Project.NameKey(newProjectName))) { + RefUpdate u = repo.updateRef(RefNames.REFS_CONFIG); + u.setForceUpdate(true); + assertThat(u.delete()).isEqualTo(Result.FORCED); + + // This should not crash. + pApi.access(); + } finally { + handle.remove(); + } + } + @Test public void addAccessSection() throws Exception { Project.NameKey p = new Project.NameKey(newProjectName);