Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349042 - Nullpointer exception in XYLayoutEditPolicy
Summary: Nullpointer exception in XYLayoutEditPolicy
Status: RESOLVED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal
Target Milestone: 1.6.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-10 10:43 EDT by Andreas Muelder CLA
Modified: 2012-09-19 12:42 EDT (History)
3 users (show)

See Also:


Attachments
Patch for bug 349042 (1.21 KB, patch)
2011-06-10 11:04 EDT, Andreas Muelder CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Muelder CLA 2011-06-10 10:43:46 EDT
Build Identifier:  I20110519-1138

A NullpointerException is thrown when moving an EditPart from a FlowLayout or ToolbarLayout to XYLayout. 
In this case, GEFs XYLayoutEditPolicy return null in getCurrentConstraintFor()
which is not handled in GMF XYLayoutEditPolicy. This can be reproduced in GMFs logic example.

This is related to GEF bug #86473

Reproducible: Always

Steps to Reproduce:
1. Create alogic example diagram
2. Create a Logic flow with a LED in it.
3. drag the LED outside of the logic flow -> the exception is thrown.
Comment 1 Andreas Muelder CLA 2011-06-10 11:04:28 EDT
Created attachment 197790 [details]
Patch for bug 349042

Patch attached...
Comment 2 Andreas Mayer CLA 2011-11-03 11:02:16 EDT
There is a similar issue with edit parts that have a non-Rectangle constraint:  

java.lang.ClassCastException: org.eclipse.gmf.runtime.diagram.ui.figures.LabelLocator cannot be cast to org.eclipse.draw2d.geometry.Rectangle
	at org.eclipse.gef.editpolicies.XYLayoutEditPolicy.getCurrentConstraintFor(XYLayoutEditPolicy.java:102)
	at org.eclipse.gef.editpolicies.XYLayoutEditPolicy.getConstraintFor(XYLayoutEditPolicy.java:55)
	at org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy.getConstraintFor(ConstrainedLayoutEditPolicy.java:244)
	at org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy.getConstraintFor(XYLayoutEditPolicy.java:226)
	at org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy.getAddCommand(ConstrainedLayoutEditPolicy.java:184)
	at org.eclipse.gef.editpolicies.LayoutEditPolicy.getCommand(LayoutEditPolicy.java:216)
	at org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy.getCommand(ConstrainedLayoutEditPolicy.java:214)
	at org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy.getCommand(XYLayoutEditPolicy.java:325)
	at org.eclipse.gef.editparts.AbstractEditPart.getCommand(AbstractEditPart.java:502)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.access$1(GraphicalEditPart.java:1)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart$1.run(GraphicalEditPart.java:482)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.getCommand(GraphicalEditPart.java:477)
	at org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy.getDropCommand(DragDropEditPolicy.java:112)
	at org.eclipse.gmf.runtime.diagram.ui.editpolicies.DiagramDragDropEditPolicy.getDropCommand(DiagramDragDropEditPolicy.java:151)
	at org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy.getCommand(DragDropEditPolicy.java:75)
	at org.eclipse.gef.editparts.AbstractEditPart.getCommand(AbstractEditPart.java:502)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.access$1(GraphicalEditPart.java:1)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart$1.run(GraphicalEditPart.java:482)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.getCommand(GraphicalEditPart.java:477)
	at org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx.getCommand(DragEditPartsTrackerEx.java:63)
	at org.eclipse.gef.tools.DragEditPartsTracker.handleDragInProgress(DragEditPartsTracker.java:370)
	at org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx.handleDragInProgress(DragEditPartsTrackerEx.java:177)
	at org.eclipse.gef.tools.AbstractTool.mouseDrag(AbstractTool.java:1114)
	at org.eclipse.gef.tools.SelectionTool.mouseDrag(SelectionTool.java:538)
	at org.eclipse.gef.EditDomain.mouseDrag(EditDomain.java:259)

You can reproduce this, for example, in the Tai Pan diagram editor:

1. Create a port and give it a name.
2. Click on the name to select it.
3. Move the cursor to the name's boundaries until the cursor changes into a cross with arrowheads.
4. Now grab the label and drag it around.
5. You will see the above ClassCastException.

This issue can be fixed by adding the following to XYLayoutEditPolicy:

    @Override
    protected Rectangle getCurrentConstraintFor(GraphicalEditPart child) {
        IFigure figure = child.getFigure();
        Object constraint = figure.getParent().getLayoutManager().getConstraint(figure);
        return constraint instanceof Rectangle 
                ? (Rectangle) constraint 
                : null;
    }
Comment 3 Aurelien Pupier CLA 2012-09-19 12:42:55 EDT
commit done 13/03/12