From 335f2091275ee85e88447880cdb5148ca915ee16 Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Mon, 14 Jun 2010 08:58:32 +0200 Subject: [PATCH] NullPointerException in Git History View This occurs because these menu actions are implemented using a preference change listener. When the page is disposed, the corresponding actions are not disposed by the history framework, so the registered actions keep listening for the preference changes. To reproduce, open a Git History, then open "History" on some non- Git controlled object in order to dispose the page. Open again a Git History page, then click on the view menu -> Wrap comments (or any other action there). The fix actively disposes the registered actions when the page is disposed. Bug: 316277 Signed-off-by: Mathias Kinzler --- .../egit/ui/internal/history/GitHistoryPage.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java index 59f570db..6ed15f3f 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java @@ -138,6 +138,11 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener { private CreatePatchAction createPatchAction = new CreatePatchAction(); + // we need to keep track of these actions so that we can + // dispose them when the page is disposed (the history framework + // does not do this for us) + private final List actionsToDispose = new ArrayList(); + /** * Determine if the input can be shown in this viewer. * @@ -731,6 +736,7 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener { } }; a.apply(a.isChecked()); + actionsToDispose.add(a); return a; } @@ -742,25 +748,30 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener { } }; a.apply(a.isChecked()); + actionsToDispose.add(a); return a; } private IAction createShowComment() { - return new BooleanPrefAction(SHOW_COMMENT, + BooleanPrefAction a = new BooleanPrefAction(SHOW_COMMENT, UIText.ResourceHistory_toggleRevComment) { void apply(final boolean value) { layout(); } }; + actionsToDispose.add(a); + return a; } private IAction createShowFiles() { - return new BooleanPrefAction(SHOW_FILES, + BooleanPrefAction a = new BooleanPrefAction(SHOW_FILES, UIText.ResourceHistory_toggleRevDetail) { void apply(final boolean value) { layout(); } }; + actionsToDispose.add(a); + return a; } private void createStandardActions() { @@ -801,6 +812,10 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener { public void dispose() { Repository.removeAnyRepositoryChangedListener(this); + // dispose of the actions (the history framework doesn't do this for us) + for (BooleanPrefAction action: actionsToDispose) + action.dispose(); + actionsToDispose.clear(); cancelRefreshJob(); if (popupMgr != null) { for (final IContributionItem i : popupMgr.getItems()) { @@ -1106,6 +1121,7 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener { } public void dispose() { + // stop listening prefs.removePropertyChangeListener(this); } } -- 2.11.4.GIT