Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2015-09-12 22:24:38 +0000
committerAndrey Loskutov2015-09-12 22:24:38 +0000
commit56529a0c680910d78ab672f630aabad3226879ab (patch)
treeb94bf1ea4104d02fce6db0f6e9b239099eba7826
parentc575f5b76fe2937ecaed8dbe45da62eee3a737e1 (diff)
downloadegit-56529a0c680910d78ab672f630aabad3226879ab.tar.gz
egit-56529a0c680910d78ab672f630aabad3226879ab.tar.xz
egit-56529a0c680910d78ab672f630aabad3226879ab.zip
Fixed NPE in StagingView if no repository is selected
This is a follow up on https://git.eclipse.org/r/54672. If Staging view was opened without selecting any repository, changing any preference in any of the Git preference pages caused NPE in IndexDiffCache.getIndexDiffCacheEntry(Repository). Marked currentRepository field as Nullable and fixed all other possible NPE places. Enabled org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion to show warnings if a value with unknown nullness is used where a NonNull value is required. Change-Id: Iab52940a67fe0205e16fa6bc5027948a4d819ff2 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCache.java3
-rw-r--r--org.eclipse.egit.ui/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java37
3 files changed, 28 insertions, 14 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCache.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCache.java
index 98cd5319f2..5fa3fe8629 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCache.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCache.java
@@ -16,6 +16,7 @@ import java.util.Set;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.JobFamilies;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jgit.lib.IndexDiff;
import org.eclipse.jgit.lib.Repository;
@@ -44,7 +45,7 @@ public class IndexDiffCache {
* @return cache entry
*/
@Nullable
- public IndexDiffCacheEntry getIndexDiffCacheEntry(Repository repository) {
+ public IndexDiffCacheEntry getIndexDiffCacheEntry(@NonNull Repository repository) {
IndexDiffCacheEntry entry;
synchronized (entries) {
entry = entries.get(repository);
diff --git a/org.eclipse.egit.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.egit.ui/.settings/org.eclipse.jdt.core.prefs
index 2b21a346ed..5939995770 100644
--- a/org.eclipse.egit.ui/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.egit.ui/.settings/org.eclipse.jdt.core.prefs
@@ -67,7 +67,7 @@ org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=error
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
-org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
index 5b7b001c0e..43e954bea0 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
@@ -85,6 +85,7 @@ import org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea;
import org.eclipse.egit.ui.internal.operations.DeletePathsOperationUI;
import org.eclipse.egit.ui.internal.operations.IgnoreOperationUI;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ControlContribution;
@@ -277,6 +278,7 @@ public class StagingView extends ViewPart implements IShowInSource {
private Action compareModeAction;
+ @Nullable
private Repository currentRepository;
private Presentation presentation = Presentation.LIST;
@@ -1114,8 +1116,11 @@ public class StagingView extends ViewPart implements IShowInSource {
}
private boolean commitAndPushEnabled(boolean commitEnabled) {
- return commitEnabled
- && !currentRepository.getRepositoryState().isRebasing();
+ Repository repo = currentRepository;
+ if (repo == null) {
+ return false;
+ }
+ return commitEnabled && !repo.getRepositoryState().isRebasing();
}
private void updateIgnoreErrorsButtonVisibility() {
@@ -1146,7 +1151,12 @@ public class StagingView extends ViewPart implements IShowInSource {
if (cacheEntry != null) {
indexDiff = cacheEntry.getIndexDiff();
} else {
- indexDiff = doReload(currentRepository);
+ Repository repo = currentRepository;
+ if (repo == null) {
+ indexDiff = null;
+ } else {
+ indexDiff = doReload(repo);
+ }
}
boolean indexDiffAvailable = indexDiffAvailable(indexDiff);
boolean noConflicts = noConflicts(indexDiff);
@@ -1473,12 +1483,13 @@ public class StagingView extends ViewPart implements IShowInSource {
}
private void enableAuthorText(boolean enabled) {
- if (currentRepository != null
- && currentRepository.getRepositoryState().equals(
- RepositoryState.CHERRY_PICKING_RESOLVED))
+ Repository repo = currentRepository;
+ if (repo != null && repo.getRepositoryState()
+ .equals(RepositoryState.CHERRY_PICKING_RESOLVED)) {
authorText.setEnabled(false);
- else
+ } else {
authorText.setEnabled(enabled);
+ }
}
private void updateToolbar() {
@@ -2204,14 +2215,16 @@ public class StagingView extends ViewPart implements IShowInSource {
}
private void openSelectionInEditor(ISelection s) {
- if (s.isEmpty() || !(s instanceof IStructuredSelection))
+ Repository repo = currentRepository;
+ if (repo == null || s.isEmpty() || !(s instanceof IStructuredSelection)) {
return;
+ }
final IStructuredSelection iss = (IStructuredSelection) s;
for (Object element : iss.toList()) {
if (element instanceof StagingEntry) {
StagingEntry entry = (StagingEntry) element;
String relativePath = entry.getPath();
- String path = new Path(currentRepository.getWorkTree()
+ String path = new Path(repo.getWorkTree()
.getAbsolutePath()).append(relativePath)
.toOSString();
openFileInEditor(path);
@@ -2730,7 +2743,7 @@ public class StagingView extends ViewPart implements IShowInSource {
: false;
}
- private IndexDiffData doReload(final Repository repository) {
+ private IndexDiffData doReload(@NonNull final Repository repository) {
IndexDiffCacheEntry entry = org.eclipse.egit.core.Activator.getDefault()
.getIndexDiffCache().getIndexDiffCacheEntry(repository);
@@ -2893,8 +2906,8 @@ public class StagingView extends ViewPart implements IShowInSource {
return false;
String chIdLine = "Change-Id: I" + ObjectId.zeroId().name(); //$NON-NLS-1$
-
- if (GerritUtil.getCreateChangeId(currentRepository.getConfig())
+ Repository repo = currentRepository;
+ if (repo != null && GerritUtil.getCreateChangeId(repo.getConfig())
&& commitMessageComponent.getCreateChangeId()) {
if (message.trim().equals(chIdLine))
return false;

Back to the top