Changeset 16119 in josm


Ignore:
Timestamp:
2020-03-14T13:26:33+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #18928 - fix various crashes with empty ways

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java

    r14397 r16119  
    256256            if (w.isClosed())
    257257                throw new InvalidSelection(tr("Can not align a polygon. Abort."));
    258             nodes.addAll(w.getNodes());
    259             lines.put(w, new Line(w));
     258            if (!w.isEmpty()) {
     259                nodes.addAll(w.getNodes());
     260                lines.put(w, new Line(w));
     261            }
    260262        }
    261263        if (nodes.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r15152 r16119  
    200200                nodeList.add((Node) p);
    201201            } else if (p instanceof Way) {
    202                 if (!p.isIncomplete()) {
    203                     wayDataList.add(new WayData(((Way) p).getNodes()));
     202                Way w = (Way) p;
     203                if (!w.isIncomplete() && !w.isEmpty()) {
     204                    wayDataList.add(new WayData(w.getNodes()));
    204205                }
    205206            } else {
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r14397 r16119  
    117117
    118118        final Collection<Way> sel = new LinkedHashSet<>(ds.getSelectedWays());
    119         sel.removeIf(Way::isIncomplete);
     119        sel.removeIf(w -> w.isIncomplete() || w.isEmpty());
    120120        if (sel.isEmpty()) {
    121121            new Notification(
     
    129129        Collection<Command> c = new LinkedList<>();
    130130        for (Way w : sel) {
    131             ReverseWayResult revResult;
    132131            try {
    133                 revResult = reverseWay(w);
     132                c.addAll(reverseWay(w).getCommands());
     133            } catch (IllegalArgumentException ex) {
     134                Logging.error(ex);
    134135            } catch (UserCancelException ex) {
    135136                Logging.trace(ex);
    136137                return;
    137138            }
    138             c.addAll(revResult.getCommands());
    139139        }
    140140        UndoRedoHandler.getInstance().add(new SequenceCommand(tr("Reverse Ways"), c));
     
    145145     * @param w the way
    146146     * @return the reverse command and the tag correction commands
     147     * @throws IllegalArgumentException if sanity checks fail
    147148     * @throws UserCancelException if user cancels a reverse warning dialog
    148149     */
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r14397 r16119  
    504504            return false;
    505505
    506         sourceWays.removeIf(w -> w.isIncomplete() || w.getNodesCount() == 0);
     506        sourceWays.removeIf(w -> w.isIncomplete() || w.isEmpty());
    507507
    508508        if (!sourceWays.contains(referenceSegment.way)) {
  • trunk/src/org/openstreetmap/josm/command/ChangeCommand.java

    r14283 r16119  
    3232     * @param osm The existing primitive to modify. It must belong to a data set
    3333     * @param newOsm The new primitive
     34     * @throws IllegalArgumentException if sanity checks fail
    3435     */
    3536    public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
     
    4243     * @param osm The existing primitive to modify
    4344     * @param newOsm The new primitive
     45     * @throws IllegalArgumentException if sanity checks fail
    4446     * @since 11240
    4547     */
     
    5456        CheckParameterUtil.ensureParameterNotNull(osm, "osm");
    5557        CheckParameterUtil.ensureParameterNotNull(newOsm, "newOsm");
    56         if (newOsm instanceof Way && ((Way) newOsm).getNodesCount() == 0) {
     58        if (newOsm instanceof Way && ((Way) newOsm).isEmpty()) {
    5759            // Do not allow to create empty ways (see #7465)
    5860            throw new IllegalArgumentException(tr("New way {0} has 0 nodes", newOsm));
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r15891 r16119  
    10171017
    10181018    void fireWayNodesChanged(Way way) {
    1019         if (way.getNodesCount() > 0) {
     1019        if (!way.isEmpty()) {
    10201020            store.reindexWay(way, Way::updatePosition, Relation::updatePosition);
    10211021        }
  • trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java

    r16069 r16119  
    174174        final Stopwatch stopwatch = Stopwatch.createStarted();
    175175        for (Way way : dataSet.getWays()) {
    176             if (way.isUsable() && way.getNodesCount() == 0) {
     176            if (way.isUsable() && way.isEmpty()) {
    177177                printError("WARN - ZERO NODES", "Way %s has zero nodes", way);
    178178            } else if (way.isUsable() && way.getNodesCount() == 1) {
  • trunk/src/org/openstreetmap/josm/data/osm/IRelation.java

    r15418 r16119  
    2222     */
    2323    int getMembersCount();
     24
     25    /**
     26     * Determines if this relation is empty, i.e. it has no members.
     27     * @return {@code true} if this relation is empty, i.e. it has no members
     28     * @since 16119
     29     */
     30    default boolean isEmpty() {
     31        return getMembersCount() == 0;
     32    }
    2433
    2534    /**
  • trunk/src/org/openstreetmap/josm/data/osm/IWay.java

    r13922 r16119  
    1717     */
    1818    int getNodesCount();
     19
     20    /**
     21     * Determines if this way is empty, i.e. it has no nodes.
     22     * @return {@code true} if this way is empty, i.e. it has no nodes
     23     * @since 16119
     24     */
     25    default boolean isEmpty() {
     26        return getNodesCount() == 0;
     27    }
    1928
    2029    /**
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

    r16115 r16119  
    424424                    for (Long wayId : wayIds) {
    425425                        Way w = (Way) ds.getPrimitiveById(wayId, OsmPrimitiveType.WAY);
    426                         if (w != null && w.getNodesCount() > 0) { // fix #7173 (empty ways on purge)
     426                        if (w != null && !w.isEmpty()) { // fix #7173 (empty ways on purge)
    427427                            waysToJoin.add(w);
    428428                        }
     
    599599                for (int i = 0; i < joinArray.length && left != 0; ++i) {
    600600                    Way c = joinArray[i];
    601                     if (c != null && c.getNodesCount() > 0) {
     601                    if (c != null && !c.isEmpty()) {
    602602                        if (nodes == null) {
    603603                            // new ring
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r16078 r16119  
    9393    @Override
    9494    public void visit(Relation r) {
    95         if (r.isMultipolygon() && r.getMembersCount() > 0) {
     95        if (r.isMultipolygon() && !r.isEmpty()) {
    9696            List<TestError> tmpErrors = new ArrayList<>(30);
    9797            boolean hasUnexpectedWayRoles = checkMembersAndRoles(r, tmpErrors);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java

    r14143 r16119  
    126126        }
    127127
    128         if (w.getNodesCount() == 0) {
     128        if (w.isEmpty()) {
    129129            errors.add(TestError.builder(this, Severity.ERROR, EMPTY_WAY)
    130130                    .message(tr("Empty ways"))
  • trunk/src/org/openstreetmap/josm/data/validation/util/ValUtil.java

    r12865 r16119  
    3434     */
    3535    public static List<List<Way>> getWaysInCell(Way w, Map<Point2D, List<Way>> cellWays) {
    36         if (w.getNodesCount() == 0)
     36        if (w.isEmpty())
    3737            return Collections.emptyList();
    3838
  • trunk/src/org/openstreetmap/josm/gui/SelectionManager.java

    r13434 r16119  
    391391            // ways
    392392            for (Way w : ds.getWays()) {
    393                 if (!w.isSelectable() || w.getNodesCount() == 0) {
     393                if (!w.isSelectable() || w.isEmpty()) {
    394394                    continue;
    395395                }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

    r15586 r16119  
    6565        // If the user wanted to create a new relation, but hasn't added any members or
    6666        // tags, don't add an empty relation
    67         if (newRelation.getMembersCount() == 0 && !newRelation.hasKeys())
     67        if (newRelation.isEmpty() && !newRelation.hasKeys())
    6868            return;
    6969        UndoRedoHandler.getInstance().add(new AddCommand(getLayer().getDataSet(), newRelation));
Note: See TracChangeset for help on using the changeset viewer.