Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 140809

Summary: NPE in TargetingTool.updateTargetUnderMouse() when closing diagrams
Product: [Tools] GEF Reporter: Cherie Revells <crevells>
Component: GEF-Legacy GEF (MVC)Assignee: gef-inbox <gef-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Cherie Revells CLA 2006-05-09 11:11:06 EDT
A client has a situation where they have many dozen diagrams open and are arranging shapes on all them (which can be a long task).  They then close all the diagrams, without saving, and get a NPE in 
TargetingTool.updateTargetUnderMouse().

Here is part of the stack trace:
java.lang.NullPointerException
	at org.eclipse.gef.tools.TargetingTool.updateTargetUnderMouse(Unknown Source)
	at org.eclipse.gef.tools.TargetingTool.unlockTargetEditPart(Unknown Source)
	at org.eclipse.gef.tools.TargetingTool.deactivate(Unknown Source)
	at org.eclipse.gef.tools.SelectionTool.deactivate(Unknown Source)
	at org.eclipse.gef.EditDomain.setActiveTool(Unknown Source)
	at org.eclipse.gef.ui.parts.GraphicalEditor.dispose(Unknown Source)
	at com.ibm.xtools.presentation.internal.ui.parts.DiagramEditor.dispose(Unknown Source)
	at org.eclipse.ui.internal.WorkbenchPartReference.dispose(Unknown Source)
	at org.eclipse.ui.internal.EditorManager$Editor.dispose(Unknown Source)
	at org.eclipse.ui.internal.WorkbenchPage$5.run(Unknown Source)
	at org.eclipse.core.internal.runtime.InternalPlatform.run(Unknown Source)
	at org.eclipse.core.runtime.Platform.run(Unknown Source)
	at org.eclipse.ui.internal.WorkbenchPage.disposePart(Unknown Source)
	at org.eclipse.ui.internal.WorkbenchPage.closeEditor(Unknown Source)

Looking at the code, I think this could happen in TargetingTool.updateTargetUnderMouse() because getCurrentViewer() is null.  The javadoc from getCurrentViewer() says that it could return null.  I think we should add a null check on getCurrentViewer() to protect against this.
Comment 1 Randy Hudson CLA 2006-05-09 11:46:55 EDT
> java.lang.NullPointerException
>         at org.eclipse.gef.tools.TargetingTool.updateTargetUnderMouse(Unknown
> Source)
>         at org.eclipse.gef.tools.TargetingTool.unlockTargetEditPart(Unknown
> Source)
>         at org.eclipse.gef.tools.TargetingTool.deactivate(Unknown Source)

I'm having trouble reading the trace. deactivate() does not call unlockTargetEditPart in TargetingTool. Please provide steps to reproduce.
Comment 2 Cherie Revells CLA 2006-05-09 12:04:08 EDT
I couldn't figure out how unlockTargetEditPart() was called either, but that's the trace that was given.  The scenario to reproduce involves a client's application.

If getCurrentViewer() says it could return null on deactivate, is it not possible that this situation could arise?  Why can't we just add a null check when calling getCurrentViewer()?
Comment 3 Randy Hudson CLA 2006-05-09 14:27:55 EDT

*** This bug has been marked as a duplicate of 119767 ***