Changeset 5410 in josm


Ignore:
Timestamp:
2012-08-09T00:50:12+02:00 (12 years ago)
Author:
Don-vip
Message:

see #7934 - Prevents NPEs with null EastNorth, override Node.isDrawable() to check lat/lon is known, improves Node javadoc

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r5349 r5410  
    121121
    122122    /**
    123      * Create a new local node.
    124      *
     123     * Constructs a new local {@code Node} with id 0.
    125124     */
    126125    public Node() {
     
    129128
    130129    /**
    131      * Create an incomplete Node object
    132      */
    133     public Node(long id) {
     130     * Constructs an incomplete {@code Node} object with the given id.
     131     * @param id The id. Must be >= 0
     132     * @throws IllegalArgumentException if id < 0
     133     */
     134    public Node(long id) throws IllegalArgumentException {
    134135        super(id, false);
    135136    }
    136137
    137138    /**
    138      * Create new node
    139      * @param id
    140      * @param version
    141      */
    142     public Node(long id, int version) {
     139     * Constructs a new {@code Node} with the given id and version.
     140     * @param id The id. Must be >= 0
     141     * @param version The version
     142     * @throws IllegalArgumentException if id < 0
     143     */
     144    public Node(long id, int version) throws IllegalArgumentException {
    143145        super(id, version, false);
    144146    }
    145147
    146148    /**
    147      *
    148      * @param clone
     149     * Constructs an identical clone of the argument.
     150     * @param clone The node to clone
    149151     * @param clearId If true, set version to 0 and id to new unique value
    150152     */
     
    158160
    159161    /**
    160      * Create an identical clone of the argument (including the id)
     162     * Constructs an identical clone of the argument (including the id).
     163     * @param clone The node to clone, including its id
    161164     */
    162165    public Node(Node clone) {
     
    164167    }
    165168
     169    /**
     170     * Constructs a new {@code Node} with the given lat/lon with id 0.
     171     * @param latlon The {@link LatLon} coordinates
     172     */
    166173    public Node(LatLon latlon) {
    167174        super(0, false);
     
    169176    }
    170177
     178    /**
     179     * Constructs a new {@code Node} with the given east/north with id 0.
     180     * @param eastNorth The {@link EastNorth} coordinates
     181     */
    171182    public Node(EastNorth eastNorth) {
    172183        super(0, false);
     
    181192    }
    182193
    183     @Override public void visit(Visitor visitor) {
     194    @Override
     195    public void visit(Visitor visitor) {
    184196        visitor.visit(this);
    185197    }
    186198
    187     @Override public void visit(PrimitiveVisitor visitor) {
     199    @Override
     200    public void visit(PrimitiveVisitor visitor) {
    188201        visitor.visit(this);
    189202    }
    190203
    191     @Override public void cloneFrom(OsmPrimitive osm) {
     204    @Override
     205    public void cloneFrom(OsmPrimitive osm) {
    192206        boolean locked = writeLock();
    193207        try {
     
    242256    }
    243257
    244     @Override public String toString() {
     258    @Override
     259    public String toString() {
    245260        String coorDesc = isLatLonKnown() ? "lat="+lat+",lon="+lon : "";
    246261        return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " "  + coorDesc+"}";
     
    287302    public void updatePosition() {
    288303    }
     304   
     305    @Override
     306    public boolean isDrawable() {
     307        // Not possible to draw a node without coordinates.
     308        return super.isDrawable() && isLatLonKnown();
     309    }
    289310
    290311    /**
     
    298319    }
    299320
     321    /**
     322     * Get debug info for bug #3892.
     323     * @return debug info for bug #3892.
     324     * @deprecated This method will be remove by the end of 2012 if no report appears.
     325     */
    300326    public String get3892DebugInfo() {
    301327        StringBuilder builder = new StringBuilder();
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r5403 r5410  
    843843        {
    844844            Point2D p = n.getEastNorth();
    845             if (initial) {
    846                 path.moveTo(p.getX(), p.getY());
    847                 initial = false;
    848             } else {
    849                 path.lineTo(p.getX(), p.getY());
     845            if (p != null) {
     846                if (initial) {
     847                    path.moveTo(p.getX(), p.getY());
     848                    initial = false;
     849                } else {
     850                    path.lineTo(p.getX(), p.getY());
     851                }
    850852            }
    851853        }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

    r5176 r5410  
    214214            for (Node n : nodes) {
    215215                Point2D p = n.getEastNorth();
    216                 if (initial) {
    217                     poly.moveTo(p.getX(), p.getY());
    218                     initial = false;
    219                 } else {
    220                     poly.lineTo(p.getX(), p.getY());
     216                if (p != null) {
     217                    if (initial) {
     218                        poly.moveTo(p.getX(), p.getY());
     219                        initial = false;
     220                    } else {
     221                        poly.lineTo(p.getX(), p.getY());
     222                    }
    221223                }
    222224            }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r5344 r5410  
    879879            EastNorth en2 = w.getNode(1).getEastNorth();
    880880            EastNorth en3 = w.getNode(2).getEastNorth();
    881             en1 = en1.sub(en2);
    882             en2 = en2.sub(en3);
    883             return en1.north() * en2.east() - en2.north() * en1.east() > 0 ? ROUNDABOUT_LEFT : ROUNDABOUT_RIGHT;
    884         } else
    885             return NONE;
     881            if (en1 != null && en2 != null && en3 != null) {
     882                en1 = en1.sub(en2);
     883                en2 = en2.sub(en3);
     884                return en1.north() * en2.east() - en2.north() * en1.east() > 0 ? ROUNDABOUT_LEFT : ROUNDABOUT_RIGHT;
     885            }
     886        }
     887        return NONE;
    886888    }
    887889
Note: See TracChangeset for help on using the changeset viewer.