Changeset 6475 in josm


Ignore:
Timestamp:
2013-12-16T01:02:37+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9433 - NoSuchElementException in validator at upload (probably after purge of all elements of a given error)

Location:
trunk/src/org/openstreetmap/josm/data/validation/tests
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Coastlines.java

    r6336 r6475  
    88import java.util.Collection;
    99import java.util.Collections;
     10import java.util.Iterator;
    1011import java.util.LinkedList;
    1112import java.util.List;
     
    218219    public Command fixError(TestError testError) {
    219220        if (isFixable(testError)) {
    220             Way way = (Way) testError.getPrimitives().iterator().next();
    221             Way newWay = new Way(way);
    222 
    223             List<Node> nodesCopy = newWay.getNodes();
    224             Collections.reverse(nodesCopy);
    225             newWay.setNodes(nodesCopy);
    226 
    227             return new ChangeCommand(way, newWay);
     221            // primitives list can be empty if all primitives have been purged
     222            Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator();
     223            if (it.hasNext()) {
     224                Way way = (Way) it.next();
     225                Way newWay = new Way(way);
     226
     227                List<Node> nodesCopy = newWay.getNodes();
     228                Collections.reverse(nodesCopy);
     229                newWay.setNodes(nodesCopy);
     230
     231                return new ChangeCommand(way, newWay);
     232            }
    228233        }
    229234        return null;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicatedWayNodes.java

    r6241 r6475  
    66import java.util.Arrays;
    77import java.util.Collections;
     8import java.util.Iterator;
    89
    910import org.openstreetmap.josm.command.ChangeCommand;
    1011import org.openstreetmap.josm.command.Command;
    1112import org.openstreetmap.josm.data.osm.Node;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1214import org.openstreetmap.josm.data.osm.Way;
    1315import org.openstreetmap.josm.data.validation.Severity;
     
    4951    }
    5052
    51     @Override public Command fixError(TestError testError) {
    52         Way w = (Way) testError.getPrimitives().iterator().next();
    53         Way wnew = new Way(w);
    54         wnew.setNodes(null);
    55         Node lastN = null;
    56         for (Node n : w.getNodes()) {
    57             if (lastN == null) {
    58                 wnew.addNode(n);
    59             } else if (n == lastN) {
    60                 // Skip this node
    61             } else {
    62                 wnew.addNode(n);
     53    @Override
     54    public Command fixError(TestError testError) {
     55        // primitives list can be empty if all primitives have been purged
     56        Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator();
     57        if (it.hasNext()) {
     58            Way w = (Way) it.next();
     59            Way wnew = new Way(w);
     60            wnew.setNodes(null);
     61            Node lastN = null;
     62            for (Node n : w.getNodes()) {
     63                if (lastN == null) {
     64                    wnew.addNode(n);
     65                } else if (n == lastN) {
     66                    // Skip this node
     67                } else {
     68                    wnew.addNode(n);
     69                }
     70                lastN = n;
    6371            }
    64             lastN = n;
     72            if (wnew.getNodesCount() < 2)
     73                // Empty way, delete
     74                return deletePrimitivesIfNeeded(Collections.singleton(w));
     75            else
     76                return new ChangeCommand(w, wnew);
    6577        }
    66         if (wnew.getNodesCount() < 2)
    67             // Empty way, delete
    68             return deletePrimitivesIfNeeded(Collections.singleton(w));
    69         else
    70             return new ChangeCommand(w, wnew);
     78        return null;
    7179    }
    7280
    73     @Override public boolean isFixable(TestError testError) {
     81    @Override
     82    public boolean isFixable(TestError testError) {
    7483        return testError.getTester() instanceof DuplicatedWayNodes;
    7584    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java

    r6434 r6475  
    88import java.util.HashMap;
    99import java.util.HashSet;
     10import java.util.Iterator;
    1011import java.util.List;
    1112import java.util.Map;
     
    3031    protected static final int WRONG_ROUNDABOUT_HIGHWAY = 2701;
    3132    protected static final int MISSING_PEDESTRIAN_CROSSING = 2702;
    32    
     33
    3334    /**
    3435     * Classified highways in order of importance
    3536     */
    3637    protected static final List<String> CLASSIFIED_HIGHWAYS = Arrays.asList(
    37             "motorway",  "motorway_link", 
    38             "trunk",     "trunk_link", 
    39             "primary",   "primary_link", 
     38            "motorway",  "motorway_link",
     39            "trunk",     "trunk_link",
     40            "primary",   "primary_link",
    4041            "secondary", "secondary_link",
    4142            "tertiary",  "tertiary_link",
     
    5051    int cyclistWays = 0;
    5152    int carsWays = 0;
    52    
     53
    5354    /**
    5455     * Constructs a new {@code Highways} test.
     
    6162
    6263        public final String correctValue;
    63        
     64
    6465        public WrongRoundaboutHighway(Way w, String key) {
    65             super(Highways.this, Severity.WARNING, 
    66                     tr("Incorrect roundabout (highway: {0} instead of {1})", w.get("highway"), key), 
     66            super(Highways.this, Severity.WARNING,
     67                    tr("Incorrect roundabout (highway: {0} instead of {1})", w.get("highway"), key),
    6768                    WRONG_ROUNDABOUT_HIGHWAY, w);
    6869            this.correctValue = key;
    6970        }
    7071    }
    71    
     72
    7273    @Override
    7374    public void visit(Node n) {
     
    116117        }
    117118    }
    118    
     119
    119120    private void testMissingPedestrianCrossing(Node n) {
    120121        leftByPedestrians = false;
     
    124125        cyclistWays = 0;
    125126        carsWays = 0;
    126        
     127
    127128        for (Way w : OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)) {
    128129            String highway = w.get("highway");
     
    172173        }
    173174    }
    174    
     175
    175176    @Override
    176177    public boolean isFixable(TestError testError) {
     
    181182    public Command fixError(TestError testError) {
    182183        if (testError instanceof WrongRoundaboutHighway) {
    183             return new ChangePropertyCommand(testError.getPrimitives().iterator().next(),
    184                     "highway", ((WrongRoundaboutHighway) testError).correctValue);
     184            // primitives list can be empty if all primitives have been purged
     185            Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator();
     186            if (it.hasNext()) {
     187                return new ChangePropertyCommand(it.next(),
     188                        "highway", ((WrongRoundaboutHighway) testError).correctValue);
     189            }
    185190        }
    186191        return null;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java

    r6295 r6475  
    88import java.util.Collection;
    99import java.util.HashMap;
     10import java.util.Iterator;
    1011import java.util.List;
    1112import java.util.Map;
     
    3132 */
    3233public class PowerLines extends Test {
    33    
     34
    3435    protected static final int POWER_LINES = 2501;
    35    
     36
    3637    /** Values for {@code power} key interpreted as power lines */
    3738    public static final Collection<String> POWER_LINE_TAGS = Arrays.asList("line", "minor_line");
     
    4243    /** Values for {@code power} key interpreted as allowed power items */
    4344    public static final Collection<String> POWER_ALLOWED_TAGS = Arrays.asList("switch", "transformer", "busbar", "generator");
    44    
     45
    4546    private final Map<Way, String> towerPoleTagMap = new HashMap<Way, String>();
    46    
     47
    4748    private final List<PowerLineError> potentialErrors = new ArrayList<PowerLineError>();
    4849
     
    5556        super(tr("Power lines"), tr("Checks for nodes in power lines that do not have a power=tower/pole tag."));
    5657    }
    57    
     58
    5859    @Override
    5960    public void visit(Way w) {
     
    8687        }
    8788    }
    88    
     89
    8990    @Override
    9091    public void visit(Relation r) {
     
    9293            powerStations.add(r);
    9394        }
    94     }   
     95    }
    9596
    9697    @Override
    9798    public void endTest() {
    9899        for (PowerLineError e : potentialErrors) {
    99             if (!isInPowerStation(e.getNode())) {
     100            Node n = e.getNode();
     101            if (n != null && !isInPowerStation(n)) {
    100102                errors.add(e);
    101103            }
     
    103105        super.endTest();
    104106    }
    105    
     107
    106108    protected final boolean isInPowerStation(Node n) {
    107109        for (OsmPrimitive station : powerStations) {
     
    129131    public Command fixError(TestError testError) {
    130132        if (testError instanceof PowerLineError && isFixable(testError)) {
    131             return new ChangePropertyCommand(
    132                     testError.getPrimitives().iterator().next(),
    133                     "power", towerPoleTagMap.get(((PowerLineError)testError).line));
     133            // primitives list can be empty if all primitives have been purged
     134            Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator();
     135            if (it.hasNext()) {
     136                return new ChangePropertyCommand(it.next(),
     137                        "power", towerPoleTagMap.get(((PowerLineError)testError).line));
     138            }
    134139        }
    135140        return null;
     
    140145        return testError instanceof PowerLineError && towerPoleTagMap.containsKey(((PowerLineError)testError).line);
    141146    }
    142    
     147
    143148    /**
    144149     * Determines if the specified way denotes a power line.
     
    167172        return isPowerIn(n, POWER_TOWER_TAGS);
    168173    }
    169    
     174
    170175    /**
    171176     * Determines if the specified node denotes a power infrastructure allowed on a power line.
     
    176181        return isPowerIn(n, POWER_ALLOWED_TAGS);
    177182    }
    178    
     183
    179184    /**
    180185     * Helper function to check if power tags is a certain value.
     
    187192        return v != null && values != null && values.contains(v);
    188193    }
    189    
     194
    190195    protected class PowerLineError extends TestError {
    191196        private final Way line;
    192197        public PowerLineError(Node n, Way line) {
    193             super(PowerLines.this, Severity.WARNING, 
     198            super(PowerLines.this, Severity.WARNING,
    194199                    tr("Missing power tower/pole within power line"), POWER_LINES, n);
    195200            this.line = line;
    196201        }
    197202        public final Node getNode() {
    198             return (Node) getPrimitives().iterator().next();
     203            // primitives list can be empty if all primitives have been purged
     204            Iterator<? extends OsmPrimitive> it = getPrimitives().iterator();
     205            return it.hasNext() ? (Node) it.next() : null;
    199206        }
    200207    }
Note: See TracChangeset for help on using the changeset viewer.