Changeset 9087 in josm for trunk/src/org


Ignore:
Timestamp:
2015-12-05T16:09:41+01:00 (4 years ago)
Author:
Don-vip
Message:

sonar - fix some errors, mainly NPEs

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

Legend:

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

    r9074 r9087  
    700700    }
    701701
    702     private abstract class InitializationTask implements Callable<Void> {
     702    private abstract static class InitializationTask implements Callable<Void> {
    703703
    704704        private final String name;
  • trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java

    r8870 r9087  
    8181     * @param nodes Nodes to be aligned.
    8282     * @return A array of two nodes.
     83     * @throws IllegalArgumentException if nodes is empty
    8384     */
    8485    private static Node[] nodePairFurthestApart(List<Node> nodes) {
     
    9394            else
    9495                waysRef.retainAll(ref);
     96        }
     97
     98        if (waysRef == null) {
     99            throw new IllegalArgumentException();
    95100        }
    96101
  • trunk/src/org/openstreetmap/josm/actions/DistributeAction.java

    r8870 r9087  
    212212     * @param nodes nodes to distribute
    213213     * @return Commands to execute to perform action
     214     * @throws IllegalArgumentException if nodes is empty
    214215     */
    215216    private static Collection<Command> distributeNodes(Collection<Node> nodes) {
     
    234235        }
    235236
     237        if (nodea == null || nodeb == null) {
     238            throw new IllegalArgumentException();
     239        }
     240
    236241        // Remove the nodes A and B from the list of nodes to move
    237242        nodes.remove(nodea);
     
    266271            }
    267272
    268             // First move the node to A's position, then move it towards B
    269             double dx = ax - s.getEastNorth().east() + (bx-ax)*pos/num;
    270             double dy = ay - s.getEastNorth().north() + (by-ay)*pos/num;
    271 
    272             cmds.add(new MoveCommand(s, dx, dy));
    273 
    274             //remove moved node from the list
    275             nodes.remove(s);
     273            if (s != null) {
     274                // First move the node to A's position, then move it towards B
     275                double dx = ax - s.getEastNorth().east() + (bx-ax)*pos/num;
     276                double dy = ay - s.getEastNorth().north() + (by-ay)*pos/num;
     277
     278                cmds.add(new MoveCommand(s, dx, dy));
     279
     280                //remove moved node from the list
     281                nodes.remove(s);
     282            }
    276283        }
    277284
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r9067 r9087  
    765765     * @param isInner - if true, reverts the direction (for multipolygon islands)
    766766     * @return list of parts, marked with the inside orientation.
     767     * @throws IllegalArgumentException if parts is empty
    767768     */
    768769    private List<WayInPolygon> markWayInsideSide(List<Way> parts, boolean isInner) {
     
    796797                }
    797798            }
     799        }
     800
     801        if (topWay == null || topNode == null) {
     802            throw new IllegalArgumentException();
    798803        }
    799804
     
    855860
    856861        //iterate till full circle is reached
    857         while (true) {
     862        while (curWay != null) {
    858863
    859864            //add cur way
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r8931 r9087  
    418418                way = w;
    419419            }
     420        }
     421        if (way == null) {
     422            return false;
    420423        }
    421424        List<Node> oldNodes = way.getNodes();
  • trunk/src/org/openstreetmap/josm/data/osm/MultipolygonBuilder.java

    r8836 r9087  
    203203            while (true) {
    204204                boolean curWayReverse = prevNode == curWay.lastNode();
    205                 Node nextNode = (curWayReverse) ? curWay.firstNode() : curWay.lastNode();
     205                Node nextNode = curWayReverse ? curWay.firstNode() : curWay.lastNode();
    206206
    207207                //add cur way to the list
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r9072 r9087  
    267267                        addError(r, new TestError(this, Severity.WARNING, tr("Multipolygon inner way is outside"),
    268268                                INNER_WAY_OUTSIDE, Collections.singletonList(r), highlights));
    269                     } else {
     269                    } else if (outerWay != null) {
    270270                        highlights.add(outerWay.getNodes());
    271271                        addError(r, new TestError(this, Severity.WARNING, tr("Intersection between multipolygon ways"),
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java

    r9059 r9087  
    7373                }
    7474
    75                 if (!RelationSortUtils.isOneway(m)) {
     75                if (!RelationSortUtils.isOneway(m) && lastWct != null) {
    7676                    wct.direction = determineDirection(i-1, lastWct.direction, i);
    7777                    wct.linkPrev = (wct.direction != NONE);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r9073 r9087  
    140140                return REGEX.equals(this) ? contains : !contains;
    141141            case ONE_OF:
    142                 return Arrays.asList(testString.split("\\s*;\\s*")).contains(prototypeString);
     142                return testString != null && Arrays.asList(testString.split("\\s*;\\s*")).contains(prototypeString);
    143143            case BEGINS_WITH:
    144                 return testString.startsWith(prototypeString);
     144                return testString != null && testString.startsWith(prototypeString);
    145145            case ENDS_WITH:
    146                 return testString.endsWith(prototypeString);
     146                return testString != null && testString.endsWith(prototypeString);
    147147            case CONTAINS:
    148                 return testString.contains(prototypeString);
     148                return testString != null && testString.contains(prototypeString);
    149149            }
    150150
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r8926 r9087  
    370370        if (key == null || value == null) {
    371371            throwException(tr("Missing key or value attribute in tag."));
    372         }
    373         t.put(key.intern(), value.intern());
     372        } else {
     373            t.put(key.intern(), value.intern());
     374        }
    374375        jumpToEnd();
    375376    }
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r9078 r9087  
    413413            if (e == null) {
    414414                error(tr("missing layer with index {0}", idx));
    415             }
    416             if (!e.hasAttribute("name")) {
     415                return;
     416            } else if (!e.hasAttribute("name")) {
    417417                error(tr("missing mandatory attribute ''name'' for element ''layer''"));
     418                return;
    418419            }
    419420            String name = e.getAttribute("name");
     
    421422            if (!e.hasAttribute("type")) {
    422423                error(tr("missing mandatory attribute ''type'' for element ''layer''"));
     424                return;
    423425            }
    424426            String type = e.getAttribute("type");
Note: See TracChangeset for help on using the changeset viewer.