From 1595249b3c59a79f39602e3e97d43f51eeee046c Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Fri, 21 Oct 2011 13:42:35 -0400 Subject: [PATCH] Add NPE check in command handlers (fix for Bug361697) --- .../lttng/tests/state/TestStateManager.java | 20 +++++++++---------- org.eclipse.linuxtools.lttng.ui/plugin.xml | 2 +- .../handlers/CopyExperimentHandler.java | 6 +++++- .../ui/project/handlers/CopyTraceHandler.java | 6 +++++- .../project/handlers/DeleteTraceHandler.java | 6 +++++- .../project/handlers/ImportTraceHandler.java | 6 +++++- .../handlers/OpenExperimentHandler.java | 7 +++++-- .../ui/project/handlers/OpenTraceHandler.java | 6 +++++- .../handlers/RenameExperimentHandler.java | 6 +++++- .../project/handlers/RenameTraceHandler.java | 6 +++++- .../handlers/SelectTraceTypeHandler.java | 6 +++++- .../project/handlers/SelectTracesHandler.java | 6 +++++- 12 files changed, 61 insertions(+), 22 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/state/TestStateManager.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/state/TestStateManager.java index 7c31d47a5e..28023cc003 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/state/TestStateManager.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/state/TestStateManager.java @@ -30,16 +30,16 @@ public class TestStateManager extends TestCase { public void testSetTraceSelection() { String logName = "traceset/trace-15316events_nolost_newformat"; - LTTngTrace testStream = null; - try { - testStream = new LTTngTrace(logName, false); - } catch (Exception e) { +// LTTngTrace testStream = null; +// try { +// testStream = new LTTngTrace(logName, true); +// } catch (Exception e) { // e.printStackTrace(); - } - - if (testStream != null) { - LTTngTrace[] streamList = new LTTngTrace[1]; - streamList[0] = testStream; +// } +// +// if (testStream != null) { +// LTTngTrace[] streamList = new LTTngTrace[1]; +// streamList[0] = testStream; // TmfExperiment newExp = new // TmfExperiment(LttngEvent.class, logName, streamList); @@ -57,6 +57,6 @@ public class TestStateManager extends TestCase { // sb.append("\n" + event); // } // TraceDebug.debug("Events not Handled: " + sb.toString()); - } +// } } } diff --git a/org.eclipse.linuxtools.lttng.ui/plugin.xml b/org.eclipse.linuxtools.lttng.ui/plugin.xml index 54b5773b2f..995d1ff9c6 100644 --- a/org.eclipse.linuxtools.lttng.ui/plugin.xml +++ b/org.eclipse.linuxtools.lttng.ui/plugin.xml @@ -6,7 +6,7 @@ point="org.eclipse.ui.perspectives"> diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyExperimentHandler.java index 1cc0548bc6..b233b51f2e 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyExperimentHandler.java @@ -16,6 +16,7 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.wizards.CopyExperimentDialog; @@ -49,7 +50,10 @@ public class CopyExperimentHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure there is only selection and that it is an experiment fExperiment = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyTraceHandler.java index 850d64dd55..5fba9f8a44 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/CopyTraceHandler.java @@ -16,6 +16,7 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; @@ -49,7 +50,10 @@ public class CopyTraceHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure a trace is selected fTrace = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/DeleteTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/DeleteTraceHandler.java index b8886fbbd6..711a431181 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/DeleteTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/DeleteTraceHandler.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; @@ -61,7 +62,10 @@ public class DeleteTraceHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure selection contains only traces fSelection = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/ImportTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/ImportTraceHandler.java index 274785dc6b..ea792a302c 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/ImportTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/ImportTraceHandler.java @@ -16,6 +16,7 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.wizard.WizardDialog; @@ -50,7 +51,10 @@ public class ImportTraceHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); TmfTraceFolder traceFolder = null; if (selection instanceof TreeSelection) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenExperimentHandler.java index 102f1d40c7..715ca40fc4 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenExperimentHandler.java @@ -19,6 +19,7 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.tmf.event.TmfEvent; import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; @@ -36,7 +37,6 @@ import org.eclipse.ui.PlatformUI; /** * OpenExperimentHandler *

- * TODO: Implement me. Please. */ public class OpenExperimentHandler extends AbstractHandler { @@ -57,7 +57,10 @@ public class OpenExperimentHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is an experiment fExperiment = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenTraceHandler.java index e672b92bdb..fa3414733f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/OpenTraceHandler.java @@ -19,6 +19,7 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IResource; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.tmf.event.TmfEvent; import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; @@ -66,7 +67,10 @@ public class OpenTraceHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is a trace fTrace = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameExperimentHandler.java index 27dabd81bf..7a8e9389d5 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameExperimentHandler.java @@ -16,6 +16,7 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.wizards.RenameExperimentDialog; @@ -48,7 +49,10 @@ public class RenameExperimentHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure there is only selection and that it is an experiment fExperiment = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameTraceHandler.java index 40ba686a53..be6233b4d6 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/RenameTraceHandler.java @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.window.Window; import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; @@ -65,7 +66,10 @@ public class RenameTraceHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure there is only selection and that it is an experiment fTrace = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTraceTypeHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTraceTypeHandler.java index cac81117c2..2baa92595d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTraceTypeHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTraceTypeHandler.java @@ -21,6 +21,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.tmf.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; @@ -69,7 +70,10 @@ public class SelectTraceTypeHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure selection contains only traces fSelection = null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTracesHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTracesHandler.java index 9a6493939a..03b1f065c7 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTracesHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/handlers/SelectTracesHandler.java @@ -16,6 +16,7 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; @@ -52,7 +53,10 @@ public class SelectTracesHandler extends AbstractHandler { // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); - ISelection selection = part.getSite().getSelectionProvider().getSelection(); + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) + return false; + ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is an experiment fExperiment = null; -- 2.34.1