Bug 485010 - "/ by zero" ArithmeticException in EdgeLabelQuery center computation
Summary: "/ by zero" ArithmeticException in EdgeLabelQuery center computation
Status: CLOSED FIXED
Alias: None
Product: Sirius
Classification: Modeling
Component: Diagram (show other bugs)
Version: 3.1.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 4.1.1   Edit
Assignee: Steve Monnier CLA
QA Contact: Pierre Guilet CLA
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks: 510851 515553 518437 518439
  Show dependency tree
 
Reported: 2015-12-30 05:45 EST by Maxime Porhel CLA
Modified: 2017-06-30 02:32 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Porhel CLA 2015-12-30 05:45:43 EST
Steps to reproduce: 
> In a runtime, on master, open the docbook sample VSP
> open the sample aird model
> open the obvious diagram and create a chapter, a big section, a medium section, a tiny section and a note
> open the evoluate view diagram
> select "Sect2" and try to move it

You will get the following stack
> org.eclipse.core.commands.ExecutionException: While executing ... exception occurred
> at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(:524)
> at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramCommandStack.exe..(71
> ...
> Caused by: java.lang.ArithmeticException: / by zero
>	at java.math.BigDecimal.divideAndRound(BigDecimal.java:4106)
>	at java.math.BigDecimal.divide(BigDecimal.java:5153)
>	at java.math.BigDecimal.divide(BigDecimal.java:1561)
>       at org.eclipse.draw2d.geometry.PrecisionGeometry.preciseDivide(l48)
>	at org.eclipse.draw2d.geometry.Vector.getAngle(Vector.java:168)
>	at oesd.ui.internal.edit.parts.locator.EdgeLabelQuery.getSameLineStatus(l507)

For the current case, both vectors are horizontal (and the edge is hidden, we see only the arrow), it seems we might use referenceVector.isParallelTo(vector) and then check the horizontallity/verticallity and direction before computing the angle.
Comment 1 Maxime Porhel CLA 2016-01-04 10:17:39 EST
Another scenario:
> Create a project
> Copy 2182.x files from oe.sirius.tests.junit/data/unit/mappings/edges_on_edges
> Open 2182.aird
> Open the diagram new doremi-2182_TC1
> Try to move the node C1 (linked to C0)
> KO -> same stack than the description. 

Same kind of scenario: an edge whose segment are not visible due to the source/target locations. No visible or horizontal segments causing the / by zero error in getAngle.
Comment 2 Maxime Porhel CLA 2016-01-04 10:42:20 EST
Another stack: 
> org.eclipse.core.commands.ExecutionException:
> While executing the operation, an exception occurred
>      at org.eclipse.core.commands.operations.DefaultOperationHistory
>                .execute(DefaultOperationHistory.java:524)
>      at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramCommandStack
>                .execute(DDiagramCommandStack.java:71)
>      at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramCommandStack
>                .execute(DDiagramCommandStack.java:52)
>      at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack
>               .execute(DiagramCommandStack.java:156)
>      at org.eclipse.gef.tools.AbstractTool
>           .executeCommand(AbstractTool.java:425)
>      at org.eclipse.gef.tools.AbstractTool
>           .executeCurrentCommand(AbstractTool.java:438)
>      at org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx
>           .executeCurrentCommand(DragEditPartsTrackerEx.java:151)
>      at org.eclipse.gef.tools.DragEditPartsTracker
>           .performDrag(DragEditPartsTracker.java:496)
>      at org.eclipse.gef.tools.DragEditPartsTracker
>           .handleButtonUp(DragEditPartsTracker.java:351)
>      at org.eclipse.sirius.diagram.ui.tools.internal.ui.SnapToAllDragEditPartsTracker
>           .handleButtonUp(SnapToAllDragEditPartsTracker.java:101)
>      at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java:1200)
> ...
>      at org.eclipse.gef.ui.parts.DomainEventDispatcher
>           .dispatchMouseReleased(DomainEventDispatcher.java:380)
> Caused by: java.lang.ArithmeticException: / by zero
>    at java.math.BigDecimal.divideAndRound(BigDecimal.java:4106)
>    at java.math.BigDecimal.divide(BigDecimal.java:5153)
>    at java.math.BigDecimal.divide(BigDecimal.java:1561)
>    at org.eclipse.draw2d.geometry.PrecisionGeometry.preciseDivide(l48)
>    at org.eclipse.draw2d.geometry.Vector.getAngle(Vector.java:168)
>    at oesd.ui.internal.edit.parts.locator.EdgeLabelQuery
>                       .getVectorForSegmentMoveCase (EdgeLabelQuery.java:414)
>    at oesd.internal.edit.parts.locator.EdgeLabelQuery
>                       .calculateNewCenterLocation(EdgeLabelQuery.java:350)
>    at oesd.ui.internal.edit.parts.locator.EdgeLabelQuery
>                       .calculateGMFLabelOffset(EdgeLabelQuery.java:243)
>    at oesd.ui.internal.edit.commands.SetLabelsOffsetOperation
>                       .computeGMFLabelOffset(SetLabelsOffsetOperation.java:150)
>    at oesd.ui.internal.edit.commands.SetLabelsOffsetOperation
>                       .computeGMFLabelsOffset(SetLabelsOffsetOperation.java:124)
>    at oesd.ui.internal.edit.commands.SetLabelsOffsetOperation
>                       .setLabelsToUpdate(SetLabelsOffsetOperation.java:109)
>    at oesd.ui.graphical.edit.policies.SetConnectionBendpointsAndLabelCommmand
>                       .setLabelsToUpdate(line 66)
>    at oesd.ui.graphical.edit.policies.SetConnectionBendpointsAccordingToDraw2DCommand
>                       .setLabelsToUpdate(line 151)
>    at oesd.ui.internal.edit.commands.ChangeBendpointsOfEdgesCommand
>                      .getBendpointsChangedCommand(line 250)
> ...
>    at org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand
>                      .doExecute
>    at org.eclipse.core.commands.operations.DefaultOperationHistory
                       .execute(DefaultOperationHistory.java:516)
But we do not have the scenario for this one. 


This stack is different from the other ones, look at the command of stack from the bug description: 
> Caused by: java.lang.ArithmeticException: / by zero
>  at java.math.BigDecimal.divideAndRound(BigDecimal.java:4106)
>  at java.math.BigDecimal.divide(BigDecimal.java:5153)
>  at java.math.BigDecimal.divide(BigDecimal.java:1561)
>  at org.eclipse.draw2d.geometry.PrecisionGeometry.preciseDivide(48)
>  at org.eclipse.draw2d.geometry.Vector.getAngle(Vector.java:168)
>  at EdgeLabelQuery.getSameLineStatus(EdgeLabelQuery.java:507)
>  at EdgeLabelQuery.getVectorFromOldToNewForSegmentsOnSameLine(457)
>  at EdgeLabelQuery.calculateNewCenterLocation(EdgeLabelQuery.java:328)
>  at EdgeLabelQuery.calculateGMFLabelOffset(EdgeLabelQuery.java:243)
>  at oesd.ui.internal.edit.commands.SetLabelsOffsetOperation.computeGMFLabelOffset 150
> at oesd.ui.internal.edit.commands.SetLabelsOffsetOperation.computeGMFLabelsOffset 124
>  at oesd.ui.internal.edit.commands.SetLabelsOffsetOperation.setLabelsToUpdate 109
>  at SetConnectionBendpointsAndLabelCommmand.setLabelsToUpdate 66
>  at SetConnectionBendpointsAccordingToExtremityMoveCommmand.setLabelsToUpdate 73
>  at ChangeBendpointsOfEdgesCommand.getBendpointsChangedCommand 275
>  at ChangeBendpointsOfEdgesCommand.completeCommandWithBendpointsChangedCommand 165
>  at ChangeBendpointsOfEdgesCommand.doExecuteWithResult 120
...




at oesd.ui.internal.edit.parts.locator.EdgeLabelQuery.getSameLineStatus(l50
Comment 3 Eclipse Genie CLA 2016-10-05 09:39:34 EDT
New Gerrit change created: https://git.eclipse.org/r/82524
Comment 5 Steve Monnier CLA 2016-10-14 12:12:45 EDT
The fix has been committed but a test should be added.
Comment 6 Eclipse Genie CLA 2016-10-19 05:01:15 EDT
New Gerrit change created: https://git.eclipse.org/r/83504
Comment 8 Laurent Redor CLA 2016-10-20 05:48:53 EDT
Test has been added by Pierre Guilet.
Comment 9 Pierre-Charles David CLA 2016-10-26 04:29:01 EDT
Available in Sirius 4.1.1, see https://wiki.eclipse.org/Sirius/4.1.1
Comment 10 Laurent Redor CLA 2017-06-30 02:30:03 EDT
(In reply to Maxime Porhel from comment #1)
> Another scenario:
> > Create a project
> > Copy 2182.x files from oe.sirius.tests.junit/data/unit/mappings/edges_on_edges
> > Open 2182.aird
> > Open the diagram new doremi-2182_TC1
> > Try to move the node C1 (linked to C0)
> > KO -> same stack than the description. 
> 
> Same kind of scenario: an edge whose segment are not visible due to the
> source/target locations. No visible or horizontal segments causing the / by
> zero error in getAngle.

The files can be found here : http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius.tests.junit/data/unit/mappings/edges_on_edges?h=v3.1.x
Comment 11 Laurent Redor CLA 2017-06-30 02:32:59 EDT
(In reply to Laurent Redor from comment #10)
> 
> The files can be found here :
> http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.
> eclipse.sirius.tests.junit/data/unit/mappings/edges_on_edges?h=v3.1.x

The files compatible with this version are http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius.tests.junit/data/unit/mappings/edges_on_edges?h=v4.1.x