Changeset 35908 in osm


Ignore:
Timestamp:
2022-02-07T15:39:46+01:00 (2 years ago)
Author:
taylor.smock
Message:

building_tools: Add NPE check in EDT along with a defensive copy

This fixes #21833: NPE: Cannot invoke "org.openstreetmap.josm.data.coor.EastNorth.east()".
This is caused by something either calling the reset method *or* one of the
methods for calculating the EastNorth returning null.

In any case, we fix the potential race condition by making a defensive copy of
the en array, and then checking the defensive copy for nulls in the EDT,
where appropriate.

Location:
applications/editors/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/Building.java

    r35668 r35908  
    210210
    211211    public void paint(Graphics2D g, MapView mv) {
    212         if (len == 0)
     212        // Make a local copy to avoid other threads resetting what we are drawing.
     213        // See JOSM #21833 for at least one instance where _something_ happens to cause
     214        // an NPE here.
     215        final EastNorth[] temporaryEnArray = Arrays.copyOf(en, en.length);
     216        if (len == 0 || temporaryEnArray[0] == null || temporaryEnArray[1] == null) {
    213217            return;
     218        }
    214219        GeneralPath b = new GeneralPath();
    215         Point pp1 = mv.getPoint(eastNorth2latlon(en[0]));
    216         Point pp2 = mv.getPoint(eastNorth2latlon(en[1]));
     220        Point pp1 = mv.getPoint(eastNorth2latlon(temporaryEnArray[0]));
     221        Point pp2 = mv.getPoint(eastNorth2latlon(temporaryEnArray[1]));
    217222        b.moveTo(pp1.x, pp1.y);
    218223        b.lineTo(pp2.x, pp2.y);
    219         if (ToolSettings.Shape.RECTANGLE == ToolSettings.getShape()) {
    220             Point pp3 = mv.getPoint(eastNorth2latlon(en[2]));
    221             Point pp4 = mv.getPoint(eastNorth2latlon(en[3]));
     224        if (ToolSettings.Shape.RECTANGLE == ToolSettings.getShape()
     225                && temporaryEnArray[2] != null && temporaryEnArray[3] != null) {
     226            Point pp3 = mv.getPoint(eastNorth2latlon(temporaryEnArray[2]));
     227            Point pp4 = mv.getPoint(eastNorth2latlon(temporaryEnArray[3]));
    222228            b.lineTo(pp3.x, pp3.y);
    223229            b.lineTo(pp4.x, pp4.y);
Note: See TracChangeset for help on using the changeset viewer.