| Summary: | NullPointerException when using TreeRouter | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Modeling] GMF-Runtime | Reporter: | Yu Li <liyu2709> | ||||||||
| Component: | General | Assignee: | Aurelien Pupier <apupier> | ||||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | ahunter.eclipse, apupier, orgler | ||||||||
| Version: | unspecified | ||||||||||
| Target Milestone: | 1.5.0 | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Windows 7 | ||||||||||
| Whiteboard: | |||||||||||
| Attachments: |
|
||||||||||
Hi, I can't reproduce your issue. Which version of GMF are you using? I am on Windows Vista, you are using Windows 7, did you already tried reproduce it on Vista? Ho wdo you configure to use TreeRouter? To activate it, I need to modify RelationshipEditPart, Relationship2EditPart. The NPE pop up a window or is it only in the log that you have the error? Thanks for report Regards, Aurelien (In reply to comment #1) > Hi, > > I can't reproduce your issue. > > Which version of GMF are you using? > > I am on Windows Vista, you are using Windows 7, did you already tried reproduce > it on Vista? > > Ho wdo you configure to use TreeRouter? To activate it, I need to modify > RelationshipEditPart, Relationship2EditPart. > > The NPE pop up a window or is it only in the log that you have the error? > > Thanks for report > Regards, > Aurelien Hi, According to my test a short while ago, the NullPointerException remains reproducible. I'm using GMF SDK 2.3.0.v20100508 and Windows 7, but haven't tried on Vista. To configure to use TreeRouter, you need only to modify org.eclipse.gmf.examples.mindmap.rcp.diagram.preferences.DiagramPreferenceInitializer.java as described in step 2. The error message will appear on the console of the eclipse workbench, from which the mindmap application is started. Regards, Yu I can reproduce this with windows 7 and the Helios 3.6.2 GMF-Builds ().
Please note: The error doesn't occur on every creation of a connection but is somewhat random. But when trying to create 10 connections, be assured at least once there will be the mentioned null-pointer-exception.
I tried to track this down by adding a breakpoint to the first line of the method
org.eclipse.gmf.runtime.draw2d.ui.internal.routers.TreeRouter.getTargetAnchorRelativeBounds(Connection)
with the following condition:
conn.getTargetAnchor().getOwner()==null
(This is where Yu Li has his NPE in line 130 of the TreeRouter.java).
I think the problem is caused in TreeRouter.invalidate-Method:
public void invalidate(Connection conn) {
if (conn.getSourceAnchor() == null || conn.getSourceAnchor().getOwner() == null ||
conn.getTargetAnchor() == null || conn.getTargetAnchor().getOwner() == null)
return;
ListIterator li = connectionList.listIterator();
while (li.hasNext()) {
Connection connNext = (Connection)li.next();
if (!trunkVertexEqual(connNext, conn)) {
updateConstraint(connNext);
}
}
}
There is a check if conn.getTargetAnchor().getOwner() is null. But this is done on the conn-Object, whereas some lines further-down updateConstraint is called with some Connection from the connectionList.
When having the mentioned NPE, the situation while being in the invalidate-Method is as follows:
conn.getSourceAnchor() and conn.getTargetAnchor() are both the same SlideableAnchor pointing to a DefaultSizeNodeFigure. Therefore in the first line of invalidate everything is fine
The connectionList consists of one single PolyLineConnection. This connNext-Object has the same SlideableAnchor as its source as the conn-Object. But the target of the connNext-Object points to an XYAnchor. And calling the getOwner() method of an XYAnchor returns null. This is what leads to the NPE later on in the getTargetAnchorRelativeBounds-Method.
My proposed fix for this is to check the owner of the sourceAnchor and targetAnchor before calling udpateConstraint on connNext. I've attached a patch that fixes the problem on the mindmap-sample.
Yu Li: Could you please verify?
I'd propse to bring this into 3.7, since the bug is really annoying when using the tree-router...
Best regards
Johannes Michler
Horus software GmbH
Incorporating the Power of Knowledge from Business Communities: http://www.horus.biz
Created attachment 193820 [details]
propsed patch for gmf 1.4.2_v20101217-0030
fix according to my comment. Please verify if this fixes the bug and if it has any negative side-effects...
Thanks, Johannes, the patch works according to my test. It would be fine if this patch can be incorporated into the new GMF version... (In reply to comment #5) > Thanks, Johannes, the patch works according to my test. It would be fine if > this patch can be incorporated into the new GMF version... Thanks for the patch Johannes I will try to take a look at this next week Created attachment 193960 [details]
second version of patch
I attach another patch. You were checking if the targetAnchor on ConneExt is null and not different from null.
Can you check that it is what you wanted to do?
Can you also provide a test case?
Regards,
Created attachment 193966 [details]
fix:check for !=null instead of ==null on every parameter
Of cause I meant to execute the updateConstraint-Method only if source and target anchor and their owner are NOT null. So this was a typo, thank you for fixing it. But you just fixed one check, I've fixed the second too...
Yu Li provided a test-case, unfortunately I have no better or always reproducible way to test this :-(
Best regards
Johannes Michler
patch applied Comment on attachment 193966 [details]
fix:check for !=null instead of ==null on every parameter
Add iplog tag for Indigo since the patch came from a non committer.
|
Build Identifier: 20100617-1415 The following NullPointerException appears when using TreeRouter in GMF: java.lang.NullPointerException at org.eclipse.gmf.runtime.draw2d.ui.internal.routers.TreeRouter.getTargetAnchorRelativeBounds(TreeRouter.java:130) at org.eclipse.gmf.runtime.draw2d.ui.internal.routers.TreeRouter.getTrunkLocation(TreeRouter.java:154) at org.eclipse.gmf.runtime.draw2d.ui.internal.routers.TreeRouter.updateConstraint(TreeRouter.java:216) at org.eclipse.gmf.runtime.draw2d.ui.internal.routers.TreeRouter.invalidate(TreeRouter.java:115) at org.eclipse.gmf.runtime.draw2d.ui.internal.routers.ForestRouter.invalidate(ForestRouter.java:98) at org.eclipse.draw2d.PolylineConnection.revalidate(PolylineConnection.java:225) at org.eclipse.draw2d.PolylineConnection.setTargetAnchor(PolylineConnection.java:314) at org.eclipse.gef.editpolicies.FeedbackHelper.setAnchor(FeedbackHelper.java:85) at org.eclipse.gef.editpolicies.FeedbackHelper.update(FeedbackHelper.java:99) at org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy.showCreationFeedback(GraphicalNodeEditPolicy.java:282) at org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy.showSourceFeedback(GraphicalNodeEditPolicy.java:293) at org.eclipse.gef.editparts.AbstractEditPart.showSourceFeedback(AbstractEditPart.java:1046) at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.showSourceFeedback(GraphicalEditPart.java:1380) at org.eclipse.gef.tools.AbstractConnectionCreationTool.showSourceFeedback(AbstractConnectionCreationTool.java:377) at org.eclipse.gef.tools.AbstractConnectionCreationTool.handleMove(AbstractConnectionCreationTool.java:319) at org.eclipse.gmf.runtime.diagram.ui.tools.ConnectionCreationTool.handleMove(ConnectionCreationTool.java:393) at org.eclipse.gef.tools.AbstractConnectionCreationTool.handleDrag(AbstractConnectionCreationTool.java:265) at org.eclipse.gef.tools.ConnectionCreationTool.handleButtonDown(ConnectionCreationTool.java:83) at org.eclipse.gef.tools.AbstractTool.mouseDown(AbstractTool.java:1097) at org.eclipse.gef.EditDomain.mouseDown(EditDomain.java:245) at org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMousePressed(DomainEventDispatcher.java:348) at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseDown(LightweightSystem.java:523) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:185) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427) at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.gmf.examples.mindmap.rcp.diagram.application.MindmapApplication.run(MindmapApplication.java:18) ... ... Reproducible: Always Steps to Reproduce: 1. Checkout org.eclipse.gmf.examples.mindmap.rcp.diagram, ...mindmap.edit and ...mindmap from CVS. 2. Change the code line "DiagramConnectionsPreferencePage.initDefaults(store);" to "store.setDefault( IPreferenceConstants.PREF_LINE_STYLE, Routing.TREE);" in org.eclipse.gmf.examples.mindmap.rcp.diagram.preferences.DiagramPreferenceInitializer.java 3. Open an example mindmap editor, create a topic, and click "Dependency" on the palette 4. Click on the topic, drag mouse to white space (the feedback will be shown), and then cancell the creation by clicking on white space 5. The NullPointerException appears while repeating step 4.