From ae215605a2dea2c1b13011e5e82fa29d9e3fe46a Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Tue, 15 Mar 2016 00:18:55 +0100 Subject: Fix NPE in RepositoriesViewPropertyTester Bug: 489602 Change-Id: If35a2b22aeb34cf15afcf33410d34c7b22308f62 Signed-off-by: Matthias Sohn --- .../tree/RepositoriesViewPropertyTester.java | 48 ++++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/RepositoriesViewPropertyTester.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/RepositoriesViewPropertyTester.java index d4cc1352b1..6930020b10 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/RepositoriesViewPropertyTester.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/RepositoriesViewPropertyTester.java @@ -48,14 +48,22 @@ public class RepositoriesViewPropertyTester extends PropertyTester { return false; RepositoryTreeNode node = (RepositoryTreeNode) receiver; - if (property.equals("isBare")) //$NON-NLS-1$ - return node.getRepository().isBare(); + Repository repository = node.getRepository(); + if (repository == null) { + return false; + } + + if (property.equals("isBare")) { //$NON-NLS-1$ + return repository.isBare(); + } - if (property.equals("containsHead")) //$NON-NLS-1$ - return containsHead(node); + if (property.equals("containsHead")) {//$NON-NLS-1$ + return containsHead(repository); + } - if (ResourcePropertyTester.testRepositoryState(node.getRepository(), property)) + if (ResourcePropertyTester.testRepositoryState(repository, property)) { return true; + } if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) @@ -63,20 +71,18 @@ public class RepositoriesViewPropertyTester extends PropertyTester { Ref ref = (Ref) node.getObject(); try { if (ref.getName().startsWith(Constants.R_REFS)) { - return ref.getName().equals( - node.getRepository().getFullBranch()); + return ref.getName().equals(repository.getFullBranch()); } else if (ref.getName().equals(Constants.HEAD)) { return true; } else { String leafname = ref.getLeaf().getName(); if (leafname.startsWith(Constants.R_REFS) - && leafname.equals(node.getRepository() - .getFullBranch())) { + && leafname.equals(repository.getFullBranch())) { return true; } else { ObjectId objectId = ref.getLeaf().getObjectId(); - return objectId != null && objectId.equals( - node.getRepository().resolve(Constants.HEAD)); + return objectId != null && objectId + .equals(repository.resolve(Constants.HEAD)); } } } catch (IOException e) { @@ -95,8 +101,8 @@ public class RepositoriesViewPropertyTester extends PropertyTester { RemoteConfig rconfig; try { - rconfig = new RemoteConfig( - node.getRepository().getConfig(), configName); + rconfig = new RemoteConfig(repository.getConfig(), + configName); } catch (URISyntaxException e2) { return false; } @@ -111,8 +117,8 @@ public class RepositoriesViewPropertyTester extends PropertyTester { RemoteConfig rconfig; try { - rconfig = new RemoteConfig( - node.getRepository().getConfig(), configName); + rconfig = new RemoteConfig(repository.getConfig(), + configName); } catch (URISyntaxException e2) { return false; } @@ -123,15 +129,13 @@ public class RepositoriesViewPropertyTester extends PropertyTester { } } if (property.equals("canStash")) { //$NON-NLS-1$ - Repository rep = node.getRepository(); - return rep.getRepositoryState().canCommit(); + return repository.getRepositoryState().canCommit(); } if (property.equals("canMerge")) { //$NON-NLS-1$ - Repository rep = node.getRepository(); - if (rep.getRepositoryState() != RepositoryState.SAFE) + if (repository.getRepositoryState() != RepositoryState.SAFE) return false; try { - String branch = rep.getFullBranch(); + String branch = repository.getFullBranch(); if (branch == null) return false; // fail gracefully... return branch.startsWith(Constants.R_HEADS); @@ -148,9 +152,9 @@ public class RepositoriesViewPropertyTester extends PropertyTester { return false; } - private boolean containsHead(RepositoryTreeNode node) { + private boolean containsHead(Repository repository) { try { - return node.getRepository().resolve(Constants.HEAD) != null; + return repository.resolve(Constants.HEAD) != null; } catch (IOException e) { return false; } -- cgit v1.2.3