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

Bug 427592

Summary: PointListUtils.toSegmentArray throws NegativeArraySizeException if an empty array gets passed in
Product: [Tools] GEF Reporter: Alexander Nyßen <nyssen>
Component: GEF GeometryAssignee: Matthias Wienand <matthias.wienand>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: matthias.wienand
Version: 3.9.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Alexander Nyßen CLA 2014-02-06 13:44:15 EST
Up to now, our geometries do not really enforce that they are constructed in a reasonable way, so for instance, Polyline can be constructed with an empty list of points (coordinates). If doing so, the following code leads to an exception within PointListUtils.toSegmentArray, which does not check that the given array is not empty: 

for (BezierCurve c : new Polyline(new double[] {}).toBezier()) {
  c.getPoints();
}

We need to make this more robust by checking within toSegmentArray that the given point array has a valid length. Also we might want to check in the constructors of our geometries, that they are only created in a reasonable way (i.e. require at least 2 points for a polyline), or - if we want to retain the flexibility - that a call to toBezier() is safe also in such a scenario.
Comment 1 Matthias Wienand CLA 2014-05-23 07:51:18 EDT
I ensured that all methods in PointListUtils can handle null/empty arrays and added a test case for the Polyline#toBezier() method. Pushed to master.