Bug 396269 - [visualizer] NPE in MulticoreVisualizerCanvas.paintCanvas()
Summary: [visualizer] NPE in MulticoreVisualizerCanvas.paintCanvas()
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 8.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.2.1   Edit
Assignee: Marc Dumais CLA
QA Contact: Marc Khouzam CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-11 08:33 EST by Marc Dumais CLA
Modified: 2013-06-28 12:22 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Dumais CLA 2012-12-11 08:33:40 EST
The NPE happens on the line: 

"MulticoreVisualizerCore mcore = m_coreMap.get(core);"

Here is the stack trace:

java.lang.NullPointerException
	at java.util.Hashtable.get(Hashtable.java:334)
	at org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view.MulticoreVisualizerCanvas.paintCanvas(MulticoreVisualizerCanvas.java:494)
	at org.eclipse.cdt.visualizer.ui.canvas.BufferedCanvas.paintDoubleBuffered(BufferedCanvas.java:165)
	at org.eclipse.cdt.visualizer.ui.canvas.BufferedCanvas.paintControl(BufferedCanvas.java:135)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:230)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1303)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1327)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1312)
	at org.eclipse.swt.widgets.Control.gtk_expose_event(Control.java:2990)
	at org.eclipse.swt.widgets.Composite.gtk_expose_event(Composite.java:714)
	at org.eclipse.swt.widgets.Canvas.gtk_expose_event(Canvas.java:167)
	at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1946)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:5140)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4379)
	at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
	at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:7933)
	at org.eclipse.swt.widgets.Display.eventProc(Display.java:1197)
	at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
	at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2204)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3182)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1030)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:924)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Comment 1 Marc Dumais CLA 2012-12-11 08:43:39 EST
w/r to the following patch, I declare the following:

1) that I am authorized to submit this code change
2) that the code is 100% my own work

Proposed patch:

https://git.eclipse.org/r/9156
Comment 2 Marc Dumais CLA 2013-02-15 09:06:11 EST
Here is what seems to be happening:

At debug session startup (with multicore visualizer open) we receive a notification that a thread has started through MulticoreVisualizerEventListener.handleEvent(IStartedDMEvent event) .

At that time the visualizer model is in the process of being built.  It sometimes happen that the core the thread runs-on is not yet defined in the model.  In that case, the thread is added to the model with a null value for the VisualizerCore object.   

Moments later, when it comes time to draw the canvas, in MulticoreVisualizerCanvas.paintCanvas(), we go through the list of known threads and try to use the null VisualizerCore value to lookup the graphical object representing the core (which doesn't exist yet anyway), causing the NPE.

There are two choices I can see to fix this:
1) at the source, in MulticoreVisualizerEventListener.handleEvent(IStartedDMEvent event), we could only create the thread model object if the core it runs-on is already created in the model. 

2) in MulticoreVisualizerCanvas.paintCanvas(), we can check that a thread has a valid core associated to it, and if not give up drawing it momentarily.

Note: in either case, nothing is lost.  When the model constructs itself, it will again fetch the threads.  At that time, the corresponding cores will be known and everything will work.
Comment 3 Marc Khouzam CLA 2013-06-20 12:57:42 EDT
Committed to master.
I'll wait until after the release to commit to cdt_8_2
Comment 5 CDT Genie CLA 2013-06-28 12:22:09 EDT
*** cdt git genie on behalf of Marc Dumais ***

    Bug 396269 - [visualizer] NPE in MulticoreVisualizerCanvas.paintCanvas()
    Change-Id: Id14d62c18db200c4f71ec3e9afaa6d9a39d5a8f4
    Reviewed-on: <a  href="https://git.eclipse.org/r/9156">https://git.eclipse.org/r/9156</a>
    Reviewed-by: Marc Khouzam &lt;marc.khouzam@xxxxxxxxxxxx&gt;
    IP-Clean: Marc Khouzam &lt;marc.khouzam@xxxxxxxxxxxx&gt;
    Tested-by: Marc Khouzam &lt;marc.khouzam@xxxxxxxxxxxx&gt;

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=010f97a80d2da8a31851bfdfddc2f153c1daf973