[josm-dev] EastNorth immutable and cloning

Olivier Croquette ml at ocroquette.de
Tue Nov 16 10:22:54 GMT 2010


Hi all

While implementing my improvements for PicLayer, I came upon 2 issues in the core code.
NB: while I know other languages quite well (in particular C++ and Perl), I am a Java newbie. That may explains things ;-)

1) First, it's documented as a immutable class : 

/**
 * Northing, Easting of the projected coordinates.
 *
 * This class is immutable.
 *
 * @author Imi
 */
public class EastNorth extends Coordinate {


But Coordinate.setLocation(x,y) allows to modify the state of EastNorth instances, so in my understanding, EastNorth is mutable, and therefore the doc is wrong.

2) In NavigatableComponent :

    /**
     * @return Returns the center point. A copy is returned, so users cannot
     *      change the center by accessing the return value. Use zoomTo instead.
     */
    public EastNorth getCenter() {
        return center;
    }

The doc is misleading. With the statement "A copy is returned", I expect to get a new object each time I call this method, but it's not the case.
Either the doc should be updated, or even better IMO, the code should be changed to that it returns a new object upon calls. That would be the occasion to make EastNorth cloneable, which is not the case right now.

Please let me know your opinion on this and if I should create a track ticket.

Best regards

Olivier




More information about the josm-dev mailing list