Index: /trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java	(revision 11383)
@@ -235,5 +235,5 @@
         switch (mode) {
         case "problem":
-            return modeProblem(v);
+            return modeProblem((ValidatorBoundingXYVisitor) v);
         case "data":
             return modeData(v);
@@ -250,9 +250,9 @@
     }
 
-    private static BoundingXYVisitor modeProblem(BoundingXYVisitor v) {
+    private static BoundingXYVisitor modeProblem(ValidatorBoundingXYVisitor v) {
         TestError error = Main.map.validatorDialog.getSelectedError();
         if (error == null)
             return null;
-        ((ValidatorBoundingXYVisitor) v).visit(error);
+        v.visit(error);
         if (v.getBounds() == null)
             return null;
Index: /trunk/src/org/openstreetmap/josm/data/osm/Node.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 11383)
@@ -238,4 +238,6 @@
     @Override
     public void cloneFrom(OsmPrimitive osm) {
+        if (!(osm instanceof Node))
+            throw new IllegalArgumentException("Not a node: " + osm);
         boolean locked = writeLock();
         try {
@@ -260,4 +262,6 @@
     @Override
     public void mergeFrom(OsmPrimitive other) {
+        if (!(other instanceof Node))
+            throw new IllegalArgumentException("Not a node: " + other);
         boolean locked = writeLock();
         try {
@@ -271,5 +275,8 @@
     }
 
-    @Override public void load(PrimitiveData data) {
+    @Override
+    public void load(PrimitiveData data) {
+        if (!(data instanceof NodeData))
+            throw new IllegalArgumentException("Not a node data: " + data);
         boolean locked = writeLock();
         try {
@@ -281,5 +288,6 @@
     }
 
-    @Override public NodeData save() {
+    @Override
+    public NodeData save() {
         NodeData data = new NodeData();
         saveCommonAttributes(data);
Index: /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 11383)
@@ -1088,5 +1088,5 @@
      *
      * Both this and other must be new, or both must be assigned an OSM ID. If both this and <code>other</code>
-     * have an assigend OSM id, the IDs have to be the same.
+     * have an assigned OSM id, the IDs have to be the same.
      *
      * @param other the other primitive. Must not be null.
Index: /trunk/src/org/openstreetmap/josm/data/osm/Relation.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/Relation.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/data/osm/Relation.java	(revision 11383)
@@ -240,4 +240,6 @@
     @Override
     public void cloneFrom(OsmPrimitive osm) {
+        if (!(osm instanceof Relation))
+            throw new IllegalArgumentException("Not a relation: " + osm);
         boolean locked = writeLock();
         try {
@@ -252,4 +254,6 @@
     @Override
     public void load(PrimitiveData data) {
+        if (!(data instanceof RelationData))
+            throw new IllegalArgumentException("Not a relation data: " + data);
         boolean locked = writeLock();
         try {
@@ -271,5 +275,6 @@
     }
 
-    @Override public RelationData save() {
+    @Override
+    public RelationData save() {
         RelationData data = new RelationData();
         saveCommonAttributes(data);
Index: /trunk/src/org/openstreetmap/josm/data/osm/Way.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/Way.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/data/osm/Way.java	(revision 11383)
@@ -277,4 +277,6 @@
     @Override
     public void load(PrimitiveData data) {
+        if (!(data instanceof WayData))
+            throw new IllegalArgumentException("Not a way data: " + data);
         boolean locked = writeLock();
         try {
@@ -314,4 +316,6 @@
     @Override
     public void cloneFrom(OsmPrimitive osm) {
+        if (!(osm instanceof Way))
+            throw new IllegalArgumentException("Not a way: " + osm);
         boolean locked = writeLock();
         try {
@@ -326,5 +330,5 @@
     @Override
     public String toString() {
-        String nodesDesc = isIncomplete() ? "(incomplete)" : "nodes=" + Arrays.toString(nodes);
+        String nodesDesc = isIncomplete() ? "(incomplete)" : ("nodes=" + Arrays.toString(nodes));
         return "{Way id=" + getUniqueId() + " version=" + getVersion()+ ' ' + getFlagsAsString() + ' ' + nodesDesc + '}';
     }
Index: /trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java	(revision 11383)
@@ -54,4 +54,8 @@
     }
 
+    private static OsmPrimitive[] castPrim(AbstractPrimitive n) {
+        return n instanceof OsmPrimitive ? (new OsmPrimitive[]{(OsmPrimitive) n}) : (new OsmPrimitive[0]);
+    }
+
     @Override
     public void visitKeyValue(AbstractPrimitive n, String key, String value) {
@@ -60,5 +64,5 @@
             errors.add(TestError.builder(this, Severity.WARNING, UNTAGGED_NODE_FIXME)
                     .message(ERROR_MESSAGE, marktr("Has tag containing ''fixme'' or ''FIXME''"))
-                    .primitives((OsmPrimitive) n)
+                    .primitives(castPrim(n))
                     .build());
             return;
@@ -87,5 +91,5 @@
             errors.add(TestError.builder(this, Severity.WARNING, code)
                     .message(ERROR_MESSAGE, msg)
-                    .primitives((OsmPrimitive) n)
+                    .primitives(castPrim(n))
                     .build());
             return;
@@ -94,5 +98,5 @@
         errors.add(TestError.builder(this, Severity.WARNING, UNTAGGED_NODE_OTHER)
                 .message(ERROR_MESSAGE, marktr("Other"))
-                .primitives((OsmPrimitive) n)
+                .primitives(castPrim(n))
                 .build());
     }
Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 11383)
@@ -943,15 +943,14 @@
     @Override
     public void eventDispatched(AWTEvent event) {
-        if (isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHidingType.DYNAMIC) {
-            if (buttonsPanel != null) {
-                Rectangle b = this.getBounds();
-                b.setLocation(getLocationOnScreen());
-                if (b.contains(((MouseEvent) event).getLocationOnScreen())) {
-                    if (!buttonsPanel.isVisible()) {
-                        buttonsPanel.setVisible(true);
-                    }
-                } else if (buttonsPanel.isVisible()) {
-                    buttonsPanel.setVisible(false);
-                }
+        if (event instanceof MouseEvent && isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHidingType.DYNAMIC
+                && buttonsPanel != null) {
+            Rectangle b = this.getBounds();
+            b.setLocation(getLocationOnScreen());
+            if (b.contains(((MouseEvent) event).getLocationOnScreen())) {
+                if (!buttonsPanel.isVisible()) {
+                    buttonsPanel.setVisible(true);
+                }
+            } else if (buttonsPanel.isVisible()) {
+                buttonsPanel.setVisible(false);
             }
         }
Index: /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 11383)
@@ -280,4 +280,6 @@
     @Override
     public void mergeFrom(Layer from) {
+        if (!(from instanceof GpxLayer))
+            throw new IllegalArgumentException("not a GpxLayer: " + from);
         data.mergeFrom(((GpxLayer) from).data);
         drawHelper.dataChanged();
Index: /trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 11383)
@@ -401,4 +401,6 @@
     @Override
     public void mergeFrom(Layer from) {
+        if (!(from instanceof GeoImageLayer))
+            throw new IllegalArgumentException("not a GeoImageLayer: " + from);
         GeoImageLayer l = (GeoImageLayer) from;
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 11382)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 11383)
@@ -622,5 +622,5 @@
                 matchingRuleIndex = wayRules;
             }
-        } else {
+        } else if (osm instanceof Relation) {
             if (((Relation) osm).isMultipolygon()) {
                 matchingRuleIndex = multipolygonRules;
@@ -630,8 +630,9 @@
                 matchingRuleIndex = relationRules;
             }
-        }
-
-        // the declaration indices are sorted, so it suffices to save the
-        // last used index
+        } else {
+            throw new IllegalArgumentException("Unsupported type: " + osm);
+        }
+
+        // the declaration indices are sorted, so it suffices to save the last used index
         int lastDeclUsed = -1;
 
Index: /trunk/test/unit/org/openstreetmap/josm/data/osm/NodeTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/osm/NodeTest.java	(revision 11382)
+++ /trunk/test/unit/org/openstreetmap/josm/data/osm/NodeTest.java	(revision 11383)
@@ -80,3 +80,27 @@
         assertEquals(box1.getCenter(), new LatLon(15, 15));
     }
+
+    /**
+     * Test that {@link Node#cloneFrom} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testCloneFromIAE() {
+        new Node().cloneFrom(new Way());
+    }
+
+    /**
+     * Test that {@link Node#mergeFrom} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testMergeFromIAE() {
+        new Node().mergeFrom(new Way());
+    }
+
+    /**
+     * Test that {@link Node#load} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testLoadIAE() {
+        new Node().load(new WayData());
+    }
 }
Index: /trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java	(revision 11382)
+++ /trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java	(revision 11383)
@@ -139,3 +139,19 @@
         assertEquals(OsmPrimitiveType.RELATION, r.getDisplayType());
     }
+
+    /**
+     * Test that {@link Relation#cloneFrom} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testCloneFromIAE() {
+        new Relation().cloneFrom(new Node());
+    }
+
+    /**
+     * Test that {@link Relation#load} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testLoadIAE() {
+        new Relation().load(new NodeData());
+    }
 }
Index: /trunk/test/unit/org/openstreetmap/josm/data/osm/WayTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/osm/WayTest.java	(revision 11382)
+++ /trunk/test/unit/org/openstreetmap/josm/data/osm/WayTest.java	(revision 11383)
@@ -55,3 +55,19 @@
         assertEquals(way.getBBox(), new BBox(10, 10));
     }
+
+    /**
+     * Test that {@link Way#cloneFrom} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testCloneFromIAE() {
+        new Way().cloneFrom(new Node());
+    }
+
+    /**
+     * Test that {@link Way#load} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testLoadIAE() {
+        new Way().load(new NodeData());
+    }
 }
Index: /trunk/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java	(revision 11382)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java	(revision 11383)
@@ -23,4 +23,5 @@
 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
 import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.projection.Projections;
 import org.openstreetmap.josm.gui.widgets.HtmlPanel;
@@ -192,4 +193,12 @@
 
     /**
+     * Test that {@link GpxLayer#mergeFrom} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testMergeFromIAE() {
+        new GpxLayer(new GpxData()).mergeFrom(new OsmDataLayer(new DataSet(), "", null));
+    }
+
+    /**
      * Unit test of {@link GpxLayer#paint}.
      * @throws Exception if any error occurs
Index: /trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java	(revision 11382)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java	(revision 11383)
@@ -14,5 +14,7 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.TestUtils;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.Loader;
 import org.openstreetmap.josm.io.GpxReader;
@@ -57,3 +59,11 @@
         }
     }
+
+    /**
+     * Test that {@link GeoImageLayer#mergeFrom} throws IAE for invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testMergeFromIAE() {
+        new GeoImageLayer(null, null).mergeFrom(new OsmDataLayer(new DataSet(), "", null));
+    }
 }
