Changeset 11383 in josm


Ignore:
Timestamp:
2016-12-12T17:29:27+01:00 (7 years ago)
Author:
Don-vip
Message:

findbugs - BC_UNCONFIRMED_CAST

Location:
trunk
Files:
15 edited

Legend:

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

    r11288 r11383  
    235235        switch (mode) {
    236236        case "problem":
    237             return modeProblem(v);
     237            return modeProblem((ValidatorBoundingXYVisitor) v);
    238238        case "data":
    239239            return modeData(v);
     
    250250    }
    251251
    252     private static BoundingXYVisitor modeProblem(BoundingXYVisitor v) {
     252    private static BoundingXYVisitor modeProblem(ValidatorBoundingXYVisitor v) {
    253253        TestError error = Main.map.validatorDialog.getSelectedError();
    254254        if (error == null)
    255255            return null;
    256         ((ValidatorBoundingXYVisitor) v).visit(error);
     256        v.visit(error);
    257257        if (v.getBounds() == null)
    258258            return null;
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r11292 r11383  
    238238    @Override
    239239    public void cloneFrom(OsmPrimitive osm) {
     240        if (!(osm instanceof Node))
     241            throw new IllegalArgumentException("Not a node: " + osm);
    240242        boolean locked = writeLock();
    241243        try {
     
    260262    @Override
    261263    public void mergeFrom(OsmPrimitive other) {
     264        if (!(other instanceof Node))
     265            throw new IllegalArgumentException("Not a node: " + other);
    262266        boolean locked = writeLock();
    263267        try {
     
    271275    }
    272276
    273     @Override public void load(PrimitiveData data) {
     277    @Override
     278    public void load(PrimitiveData data) {
     279        if (!(data instanceof NodeData))
     280            throw new IllegalArgumentException("Not a node data: " + data);
    274281        boolean locked = writeLock();
    275282        try {
     
    281288    }
    282289
    283     @Override public NodeData save() {
     290    @Override
     291    public NodeData save() {
    284292        NodeData data = new NodeData();
    285293        saveCommonAttributes(data);
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r11373 r11383  
    10881088     *
    10891089     * Both this and other must be new, or both must be assigned an OSM ID. If both this and <code>other</code>
    1090      * have an assigend OSM id, the IDs have to be the same.
     1090     * have an assigned OSM id, the IDs have to be the same.
    10911091     *
    10921092     * @param other the other primitive. Must not be null.
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r11316 r11383  
    240240    @Override
    241241    public void cloneFrom(OsmPrimitive osm) {
     242        if (!(osm instanceof Relation))
     243            throw new IllegalArgumentException("Not a relation: " + osm);
    242244        boolean locked = writeLock();
    243245        try {
     
    252254    @Override
    253255    public void load(PrimitiveData data) {
     256        if (!(data instanceof RelationData))
     257            throw new IllegalArgumentException("Not a relation data: " + data);
    254258        boolean locked = writeLock();
    255259        try {
     
    271275    }
    272276
    273     @Override public RelationData save() {
     277    @Override
     278    public RelationData save() {
    274279        RelationData data = new RelationData();
    275280        saveCommonAttributes(data);
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r11292 r11383  
    277277    @Override
    278278    public void load(PrimitiveData data) {
     279        if (!(data instanceof WayData))
     280            throw new IllegalArgumentException("Not a way data: " + data);
    279281        boolean locked = writeLock();
    280282        try {
     
    314316    @Override
    315317    public void cloneFrom(OsmPrimitive osm) {
     318        if (!(osm instanceof Way))
     319            throw new IllegalArgumentException("Not a way: " + osm);
    316320        boolean locked = writeLock();
    317321        try {
     
    326330    @Override
    327331    public String toString() {
    328         String nodesDesc = isIncomplete() ? "(incomplete)" : "nodes=" + Arrays.toString(nodes);
     332        String nodesDesc = isIncomplete() ? "(incomplete)" : ("nodes=" + Arrays.toString(nodes));
    329333        return "{Way id=" + getUniqueId() + " version=" + getVersion()+ ' ' + getFlagsAsString() + ' ' + nodesDesc + '}';
    330334    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java

    r11129 r11383  
    5454    }
    5555
     56    private static OsmPrimitive[] castPrim(AbstractPrimitive n) {
     57        return n instanceof OsmPrimitive ? (new OsmPrimitive[]{(OsmPrimitive) n}) : (new OsmPrimitive[0]);
     58    }
     59
    5660    @Override
    5761    public void visitKeyValue(AbstractPrimitive n, String key, String value) {
     
    6064            errors.add(TestError.builder(this, Severity.WARNING, UNTAGGED_NODE_FIXME)
    6165                    .message(ERROR_MESSAGE, marktr("Has tag containing ''fixme'' or ''FIXME''"))
    62                     .primitives((OsmPrimitive) n)
     66                    .primitives(castPrim(n))
    6367                    .build());
    6468            return;
     
    8791            errors.add(TestError.builder(this, Severity.WARNING, code)
    8892                    .message(ERROR_MESSAGE, msg)
    89                     .primitives((OsmPrimitive) n)
     93                    .primitives(castPrim(n))
    9094                    .build());
    9195            return;
     
    9498        errors.add(TestError.builder(this, Severity.WARNING, UNTAGGED_NODE_OTHER)
    9599                .message(ERROR_MESSAGE, marktr("Other"))
    96                 .primitives((OsmPrimitive) n)
     100                .primitives(castPrim(n))
    97101                .build());
    98102    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r10627 r11383  
    943943    @Override
    944944    public void eventDispatched(AWTEvent event) {
    945         if (isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHidingType.DYNAMIC) {
    946             if (buttonsPanel != null) {
    947                 Rectangle b = this.getBounds();
    948                 b.setLocation(getLocationOnScreen());
    949                 if (b.contains(((MouseEvent) event).getLocationOnScreen())) {
    950                     if (!buttonsPanel.isVisible()) {
    951                         buttonsPanel.setVisible(true);
    952                     }
    953                 } else if (buttonsPanel.isVisible()) {
    954                     buttonsPanel.setVisible(false);
    955                 }
     945        if (event instanceof MouseEvent && isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHidingType.DYNAMIC
     946                && buttonsPanel != null) {
     947            Rectangle b = this.getBounds();
     948            b.setLocation(getLocationOnScreen());
     949            if (b.contains(((MouseEvent) event).getLocationOnScreen())) {
     950                if (!buttonsPanel.isVisible()) {
     951                    buttonsPanel.setVisible(true);
     952                }
     953            } else if (buttonsPanel.isVisible()) {
     954                buttonsPanel.setVisible(false);
    956955            }
    957956        }
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r10959 r11383  
    280280    @Override
    281281    public void mergeFrom(Layer from) {
     282        if (!(from instanceof GpxLayer))
     283            throw new IllegalArgumentException("not a GpxLayer: " + from);
    282284        data.mergeFrom(((GpxLayer) from).data);
    283285        drawHelper.dataChanged();
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r10763 r11383  
    401401    @Override
    402402    public void mergeFrom(Layer from) {
     403        if (!(from instanceof GeoImageLayer))
     404            throw new IllegalArgumentException("not a GeoImageLayer: " + from);
    403405        GeoImageLayer l = (GeoImageLayer) from;
    404406
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r11374 r11383  
    622622                matchingRuleIndex = wayRules;
    623623            }
    624         } else {
     624        } else if (osm instanceof Relation) {
    625625            if (((Relation) osm).isMultipolygon()) {
    626626                matchingRuleIndex = multipolygonRules;
     
    630630                matchingRuleIndex = relationRules;
    631631            }
    632         }
    633 
    634         // the declaration indices are sorted, so it suffices to save the
    635         // last used index
     632        } else {
     633            throw new IllegalArgumentException("Unsupported type: " + osm);
     634        }
     635
     636        // the declaration indices are sorted, so it suffices to save the last used index
    636637        int lastDeclUsed = -1;
    637638
  • trunk/test/unit/org/openstreetmap/josm/data/osm/NodeTest.java

    r11269 r11383  
    8080        assertEquals(box1.getCenter(), new LatLon(15, 15));
    8181    }
     82
     83    /**
     84     * Test that {@link Node#cloneFrom} throws IAE for invalid arguments
     85     */
     86    @Test(expected = IllegalArgumentException.class)
     87    public void testCloneFromIAE() {
     88        new Node().cloneFrom(new Way());
     89    }
     90
     91    /**
     92     * Test that {@link Node#mergeFrom} throws IAE for invalid arguments
     93     */
     94    @Test(expected = IllegalArgumentException.class)
     95    public void testMergeFromIAE() {
     96        new Node().mergeFrom(new Way());
     97    }
     98
     99    /**
     100     * Test that {@link Node#load} throws IAE for invalid arguments
     101     */
     102    @Test(expected = IllegalArgumentException.class)
     103    public void testLoadIAE() {
     104        new Node().load(new WayData());
     105    }
    82106}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java

    r11269 r11383  
    139139        assertEquals(OsmPrimitiveType.RELATION, r.getDisplayType());
    140140    }
     141
     142    /**
     143     * Test that {@link Relation#cloneFrom} throws IAE for invalid arguments
     144     */
     145    @Test(expected = IllegalArgumentException.class)
     146    public void testCloneFromIAE() {
     147        new Relation().cloneFrom(new Node());
     148    }
     149
     150    /**
     151     * Test that {@link Relation#load} throws IAE for invalid arguments
     152     */
     153    @Test(expected = IllegalArgumentException.class)
     154    public void testLoadIAE() {
     155        new Relation().load(new NodeData());
     156    }
    141157}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/WayTest.java

    r11271 r11383  
    5555        assertEquals(way.getBBox(), new BBox(10, 10));
    5656    }
     57
     58    /**
     59     * Test that {@link Way#cloneFrom} throws IAE for invalid arguments
     60     */
     61    @Test(expected = IllegalArgumentException.class)
     62    public void testCloneFromIAE() {
     63        new Way().cloneFrom(new Node());
     64    }
     65
     66    /**
     67     * Test that {@link Way#load} throws IAE for invalid arguments
     68     */
     69    @Test(expected = IllegalArgumentException.class)
     70    public void testLoadIAE() {
     71        new Way().load(new NodeData());
     72    }
    5773}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java

    r11071 r11383  
    2323import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
    2424import org.openstreetmap.josm.data.gpx.WayPoint;
     25import org.openstreetmap.josm.data.osm.DataSet;
    2526import org.openstreetmap.josm.data.projection.Projections;
    2627import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     
    192193
    193194    /**
     195     * Test that {@link GpxLayer#mergeFrom} throws IAE for invalid arguments
     196     */
     197    @Test(expected = IllegalArgumentException.class)
     198    public void testMergeFromIAE() {
     199        new GpxLayer(new GpxData()).mergeFrom(new OsmDataLayer(new DataSet(), "", null));
     200    }
     201
     202    /**
    194203     * Unit test of {@link GpxLayer#paint}.
    195204     * @throws Exception if any error occurs
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java

    r10467 r11383  
    1414import org.openstreetmap.josm.Main;
    1515import org.openstreetmap.josm.TestUtils;
     16import org.openstreetmap.josm.data.osm.DataSet;
    1617import org.openstreetmap.josm.gui.layer.GpxLayer;
     18import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1719import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.Loader;
    1820import org.openstreetmap.josm.io.GpxReader;
     
    5759        }
    5860    }
     61
     62    /**
     63     * Test that {@link GeoImageLayer#mergeFrom} throws IAE for invalid arguments
     64     */
     65    @Test(expected = IllegalArgumentException.class)
     66    public void testMergeFromIAE() {
     67        new GeoImageLayer(null, null).mergeFrom(new OsmDataLayer(new DataSet(), "", null));
     68    }
    5969}
Note: See TracChangeset for help on using the changeset viewer.