Skip to content

Commit c406f5a

Browse files
authored
Fix CoordinateList.clone() to copy correctly (#1168)
1 parent 4574422 commit c406f5a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

modules/core/src/main/java/org/locationtech/jts/geom/CoordinateList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public Coordinate[] toCoordinateArray(boolean isForward)
242242
public Object clone() {
243243
CoordinateList clone = (CoordinateList) super.clone();
244244
for (int i = 0; i < this.size(); i++) {
245-
clone.add(i, (Coordinate) this.get(i).clone());
245+
clone.set(i, (Coordinate) this.get(i).clone());
246246
}
247247
return clone;
248248
}

modules/core/src/test/java/org/locationtech/jts/geom/CoordinateListTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ public void testReverseEmpty() {
2424
checkValue(coordList().toCoordinateArray(false) );
2525
}
2626

27+
public void testClone() {
28+
CoordinateList clone = (CoordinateList) coordList(0,0,1,1,2,2).clone();
29+
checkValue(clone.toCoordinateArray(true), 0,0,1,1,2,2);
30+
}
31+
32+
//======================================
33+
2734
private void checkValue(Coordinate[] coordArray, double ... ords) {
2835

29-
assertEquals( coordArray.length * 2, ords.length);
36+
assertEquals( "list has wrong length", coordArray.length, ords.length / 2);
3037

3138
for (int i = 0 ; i < coordArray.length; i += 2) {
3239
Coordinate pt = coordArray[i];

0 commit comments

Comments
 (0)