Buggy code:
public class PolygonsSet extends AbstractRegion < Euclidean2D , Euclidean1D > { private Vector2D [ ] [ ] vertices ; public PolygonsSet ( ) { } public PolygonsSet ( final BSPTree < Euclidean2D > tree ) { } public PolygonsSet ( final Collection < SubHyperplane < Euclidean2D > > boundary ) { } public PolygonsSet ( final double xMin , final double xMax , final double yMin , final double yMax ) { } public PolygonsSet ( final double hyperplaneThickness , final Vector2D ... vertices ) { } private static Line [ ] boxBoundary ( final double xMin , final double xMax , final double yMin , final double yMax ) { } private static BSPTree < Euclidean2D > verticesToTree ( final double hyperplaneThickness , final Vector2D ... vertices ) { final int n = vertices . length ; if ( n == 0 ) { return new BSPTree < Euclidean2D > ( Boolean . TRUE ) ; } final PolygonsSet . Vertex [ ] vArray = new PolygonsSet . Vertex [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { vArray [ i ] = new PolygonsSet . Vertex ( vertices [ i ] ) ; } <START_BUG> List < PolygonsSet . Edge > edges = new ArrayList < PolygonsSet . Edge > ( ) ; <END_BUG> for ( int i = 0 ; i < n ; ++ i ) { final PolygonsSet . Vertex start = vArray [ i ] ; final PolygonsSet . Vertex end = vArray [ ( ( i + 1 ) % n ) ] ; Line line = start . sharedLineWith ( end ) ; if ( line == null ) { line = new Line ( start . getLocation ( ) , end . getLocation ( ) ) ; } edges . add ( new PolygonsSet . Edge ( start , end , line ) ) ; for ( final PolygonsSet . Vertex vertex : vArray ) { if ( ( ( vertex != start ) && ( vertex != end ) ) && ( ( FastMath . abs ( line . getOffset ( vertex . getLocation ( ) ) ) ) <= hyperplaneThickness ) ) { vertex . bindWith ( line ) ; } } } final BSPTree < Euclidean2D > tree = new BSPTree < Euclidean2D > ( ) ; PolygonsSet . insertEdges ( hyperplaneThickness , tree , edges ) ; return tree ; } private static void insertEdges ( final double hyperplaneThickness , final BSPTree < Euclidean2D > node , final List < PolygonsSet . Edge > edges ) { } private static class Vertex { private final Vector2D location ; private PolygonsSet . Edge incoming ; private PolygonsSet . Edge outgoing ; private final List < Line > lines ; public Vertex ( final Vector2D location ) { } public Vector2D getLocation ( ) { } public void bindWith ( final Line line ) { } public Line sharedLineWith ( final PolygonsSet . Vertex vertex ) { } public void setIncoming ( final PolygonsSet . Edge incoming ) { } public PolygonsSet . Edge getIncoming ( ) { } public void setOutgoing ( final PolygonsSet . Edge outgoing ) { } public PolygonsSet . Edge getOutgoing ( ) { } } private static class Edge { private final PolygonsSet . Vertex start ; private final PolygonsSet . Vertex end ; private final Line line ; private BSPTree < Euclidean2D > node ; public Edge ( final PolygonsSet . Vertex start , final PolygonsSet . Vertex end , final Line line ) { } public PolygonsSet . Vertex getStart ( ) { } public PolygonsSet . Vertex getEnd ( ) { } public Line getLine ( ) { } public void setNode ( final BSPTree < Euclidean2D > node ) { } public BSPTree < Euclidean2D > getNode ( ) { } public PolygonsSet . Vertex split ( final Line splitLine ) { } } @ Override public PolygonsSet buildNew ( final BSPTree < Euclidean2D > tree ) { } @ Override protected void computeGeometricalProperties ( ) { } public Vector2D [ ] [ ] getVertices ( ) { } private List < PolygonsSet . ComparableSegment > followLoop ( final AVLTree < ComparableSegment > . Node node , final org . apache . commons . math3 . geometry . partitioning . utilities . AVLTree < PolygonsSet . ComparableSegment > sorted ) { } private static class ComparableSegment extends Segment implements Comparable < PolygonsSet . ComparableSegment > { private OrderedTuple sortingKey ; public ComparableSegment ( final Vector2D start , final Vector2D end , final Line line ) { } public ComparableSegment ( final Vector2D start , final double dx , final double dy ) { } public int compareTo ( final PolygonsSet . ComparableSegment o ) { } @ Override public boolean equals ( final Object other ) { } @ Override public int hashCode ( ) { } } private static class SegmentsBuilder implements BSPTreeVisitor < Euclidean2D > { private org . apache . commons . math3 . geometry . partitioning . utilities . AVLTree < PolygonsSet . ComparableSegment > sorted ; public SegmentsBuilder ( ) { } public Order visitOrder ( final BSPTree < Euclidean2D > node ) { } public void visitInternalNode ( final BSPTree < Euclidean2D > node ) { } public void visitLeafNode ( final BSPTree < Euclidean2D > node ) { } private void addContribution ( final SubHyperplane < Euclidean2D > sub , final boolean reversed ) { } public org . apache . commons . math3 . geometry . partitioning . utilities . AVLTree < PolygonsSet . ComparableSegment > getSorted ( ) { } } }

Fix:
List < PolygonsSet . Edge > edges = new ArrayList < PolygonsSet . Edge > ( n ) ;