Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » NPE when closing my Graphiti editor...(...in DiagramBehavior#selectPictogramElements)
NPE when closing my Graphiti editor... [message #1240170] Wed, 05 February 2014 21:31 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi all,

I get a strange NPE when closing my Graphiti editor. It seems to be related to my properties view for some reason.
I previously had a properties view displaying my graphiti editor picture element selections and this was working fine.
I then added another property sheet page in my RCP application to display selections in a navigator / explorer view.
Both seem to work fine and with no conflict except, for some reason, when closing my Graphiti editor. I then get a NPE.
It occurs in DiagramBehavior#selectPictogramElements when the method calls diagramContainer.getGraphicalViewer().reveal(editpart) at the end.
And it's related to an internal null Control object.

As a workaround, I simply made a copy/paste of selectPictogramElements in my own XXXDiagramBehavior and catched this exception.

Any idea why this occurs and what to do to prevent this from happening ?

Kind regards,

Laurent
Re: NPE when closing my Graphiti editor... [message #1241122 is a reply to message #1240170] Fri, 07 February 2014 14:11 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Laurent,

what triggers the call to selectPictogramElements? Can you provide the call
stack of the NPE?

I would assume that the method is triggered after the editor was closed or
rather while it is closing.

Michael
Re: NPE when closing my Graphiti editor... [message #1241361 is a reply to message #1241122] Fri, 07 February 2014 21:36 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Michael,

To give you some more details, I don't get the NPE when closing the whole RCP application. Neither do I when I close an editor with an empty diagram.
The NPE occurs when I close a diagram with a picture element from which the underlying business object also corresponds to my explorer selection.
In that case, I have two property sheet pages for the same element and I guess there must be some kind of collision...

Hereafter the stack trace but I couldn't get much of it :
!ENTRY org.eclipse.ui 4 0 2014-02-07 22:27:14.756
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
	at org.eclipse.swt.SWT.error(SWT.java:4397)
	at org.eclipse.swt.SWT.error(SWT.java:4312)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at mymigratedappsmodeler.Application.start(Application.java:35)
	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:354)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.NullPointerException
	at org.eclipse.gef.ui.parts.ScrollingGraphicalViewer.reveal(ScrollingGraphicalViewer.java:75)
	at org.eclipse.graphiti.ui.editor.DiagramBehavior$5.run(DiagramBehavior.java:864)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	... 24 more


Regards,

Laurent
Re: NPE when closing my Graphiti editor... [message #1244619 is a reply to message #1241361] Wed, 12 February 2014 16:11 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Laurent,

that's hard to track, but it seems to be some late selection request, but I
can't see who triggered that. Somebody seems to call
DiagramBehavior.selectPictogramElements at a time when the editor already
closes down.

Can you check who triggers that call?

Michael
Re: NPE when closing my Graphiti editor... [message #1245844 is a reply to message #1244619] Fri, 14 February 2014 10:46 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Michael,

In debug mode, I can see that DiagramEditor.selectionChanged calls DiagramBehavior.selectPictogramElements.

The cinematic seems to be the following one :
- Double-clic on my tree item in my navigator opens the corresponding diagram.
- When closing the diagram, the current selection switches back to the tree item.
- This selection change causes a notification and as a consequence the call of DiagramEditor.selectionChanged.

Having a look to this method, it appears "editorIsActive" is true even if my editor is closing and my navigator is not an instance of CommonNavigator either.
So execution goes on until the failing call of selectPictogramElements...
Could this be improved ?

A workaround is to override selectionChanged in my DiagramEditor extension so that it simply returns when the notification comes from my navigator.

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
  if (part instanceof RepositoryNavigator)
    return;
  else
    super.selectionChanged(part, selection);
}


Regards,

Laurent
Re: NPE when closing my Graphiti editor... [message #1245904 is a reply to message #1245844] Fri, 14 February 2014 12:35 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Laurent,

not sure if that workaround really works for you as it prevents all
selection requests from this view to be ignored. I would go for a solution
to set a disposing flag at the beginning of the dispose method and check
that in selectionChanged. You could add that yourself, but I'd guess this
could also be added to the framework.

Michael
Re: NPE when closing my Graphiti editor... [message #1246022 is a reply to message #1245904] Fri, 14 February 2014 16:03 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Michael,

I guess you're right if one wants to refresh the editor depending on the navigator selection.
I set a disposing flag in DiagramEditor.dispose to serve the DiagramEditor.selectionChanged purpose.
But, selectionChanged gets called first... Sad
And doing it in DiagramEditor.close is even worse (the NPE prevents the method from being called).

Laurent
Re: NPE when closing my Graphiti editor... [message #1248453 is a reply to message #1246022] Mon, 17 February 2014 09:23 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

Finally, declaring my DiagramEditor extension as a part listener in init let me set a 'isEditorClosing' flag to be used in selectionChanged :

...
super.init(site, input);
// Detect when editor is closing for later selectionChanged to filter out related event...
getSite().getWorkbenchWindow().getPartService().addPartListener(new IPartListener() {
  @Override
  public void partActivated(IWorkbenchPart part) {}

  @Override
  public void partBroughtToTop(IWorkbenchPart part) {}

  @Override
  public void partClosed(IWorkbenchPart part) {}

  @Override
  public void partDeactivated(IWorkbenchPart part) {
    isEditorClosing = true;
  }

  @Override
  public void partOpened(IWorkbenchPart part) {}			
});


/*
 * If editor is closing, filter out selection changed event to avoid NPE. 
 */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
  if (isEditorClosing) {
    return;
  } else
    super.selectionChanged(part, selection);
}


I agree this could be part of the framework so I filled an enhancement resquest :

https://bugs.eclipse.org/bugs/show_bug.cgi?id=428227

Regards,

Laurent
Re: NPE when closing my Graphiti editor... [message #1419311 is a reply to message #1248453] Mon, 08 September 2014 12:11 Go to previous messageGo to next message
Rizwan Mohammed is currently offline Rizwan MohammedFriend
Messages: 2
Registered: July 2014
Junior Member
Hi Laurent,
I'm facing the same issue. I wanted to use the same code which you have pasted here.
I'm using a RCP application. My graphiti diagram is on a RCP view.
When I switch the perspective . I get this exception. Will this code help. ?

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (isEditorClosing) {
return;
} else
super.selectionChanged(part, selection);
}

where should I place this code. ?
In view. ?
Re: NPE when closing my Graphiti editor... [message #1419387 is a reply to message #1419311] Mon, 08 September 2014 14:29 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi,

I'm not sure I can help because my RCP application has only one perspective so I don't face any switching issue.
Moreover, my diagram is displayed in an editor. Not a view.

Nevertheless, I would try the same strategy if you're facing exactly the same issue.

I guess you can register your view as a part listener as well, to set a flag when the view gets deactivated on perspective change.

Then, I'm not sure what happens in your case.
If the NPE occurs in yourView.selectionChanged, I would indeed try the same code in your view.
If, however the NPE occurs in the perspective class (something like myPerspective.selectionChanged ?), I guess you'll have to first look for your view in the perspective before you can read its "isViewDeactivated" flag somehow.

Regards,

Laurent
Previous Topic:Drawing shapes using SWT/Draw2D
Next Topic:Moving ContainerShape onto Shape
Goto Forum:
  


Current Time: Tue Mar 19 11:19:53 GMT 2024

Powered by FUDForum. Page generated in 0.03424 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top