locationtech / jts

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.
Other
1.98k stars 443 forks source link

jts 1.15.0 regression on clone / copy #292

Open jodygarnett opened 6 years ago

jodygarnett commented 6 years ago

As part of upgrading GeoTools to use JTS 1.15.0 we have noticed a regression around the use of clone (now deprecated in favour of the new copy() method).

For a specific implementation clone is implemented as a call to copy():

class Point extends Geometry {
  ...
  /**
   * Creates and returns a full copy of this {@link Point} object.
   * (including all coordinates contained by it).
   *
   * @return a clone of this instance
   * @deprecated
   */
  public Object clone() {
    return copy();
  }

Where a specific implementation copies the data structure, but not the SRID and userData:

   public LineString copy() {
    return new LineString(points.copy(), factory);
  }

As a workaround client code can:

Geometry clone = ((Geometry)geom).clone();
clone.setSRID( ((Geometry)geom).getSRID() );
clone.setUserData( ((Geometry)geom).getUserdata() );
jodygarnett commented 6 years ago

Looking at master it appears that this issue was fixed with the introduction of:

We will need to reimplement copyInternal for any additional Geometry subclasses in client code.

jnh5y commented 6 years ago

Sounds like we might need to document this in the migration/upgrade guides? Are there any code changes to JTS?

jnh5y commented 6 years ago

Ah, we should add some unit tests... I need to get some more coffee...

dr-jts commented 6 years ago

This was fixed by https://github.com/locationtech/jts/pull/284 (in master, as @jodygarnett says. So is still a bug in 1.15 release)