Index: /trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java	(revision 2499)
+++ /trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java	(revision 2500)
@@ -2,6 +2,6 @@
 package org.openstreetmap.josm.actions;
 
+import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
 import static org.openstreetmap.josm.tools.I18n.tr;
-import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
 
 import java.awt.Dimension;
@@ -22,4 +22,6 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Version;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
 import org.openstreetmap.josm.gui.ExtendedDialog;
 import org.openstreetmap.josm.plugins.PluginHandler;
@@ -59,6 +61,19 @@
         text.append("Java version: " + System.getProperty("java.version"));
         text.append("\n\n");
+        DataSet dataset = Main.main.getCurrentDataSet();
+        if (dataset != null) {
+            text.append("Dataset consistency test:\n");
+            String result = DatasetConsistencyTest.runTests(dataset);
+            if (result.length() == 0) {
+                text.append("No problems found\n");
+            } else {
+                text.append(result);
+            }
+            text.append("\n");
+        }
+        text.append("\n");
         text.append(PluginHandler.getBugReportText());
-        text.append("\n\n");
+        text.append("\n");
+
         return text.toString();
     }
Index: /trunk/src/org/openstreetmap/josm/data/osm/BBox.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/BBox.java	(revision 2499)
+++ /trunk/src/org/openstreetmap/josm/data/osm/BBox.java	(revision 2500)
@@ -102,11 +102,11 @@
 
     public boolean inside(BBox b) {
-        if (xmin >= b.xmax)
+        if (xmin > b.xmax)
             return false;
-        if (xmax <= b.xmin)
+        if (xmax < b.xmin)
             return false;
-        if (ymin >= b.ymax)
+        if (ymin > b.ymax)
             return false;
-        if (ymax <= b.ymin)
+        if (ymax < b.ymin)
             return false;
         return true;
Index: /trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java	(revision 2500)
+++ /trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java	(revision 2500)
@@ -0,0 +1,98 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+
+/**
+ * This class can be used to run consistency tests on dataset. Any errors found will be written to provided PrintWriter
+ * <br>
+ * Texts here should not be translated because they're not intended for users but for josm developers
+ *
+ */
+public class DatasetConsistencyTest {
+
+    private final DataSet dataSet;
+    private final PrintWriter writer;
+
+    public DatasetConsistencyTest(DataSet dataSet, Writer writer) {
+        this.dataSet = dataSet;
+        this.writer = new PrintWriter(writer);
+    }
+
+    private void checkReferrers() {
+        for (Way way:dataSet.getWays()) {
+            for (Node n:way.getNodes()) {
+                if (!n.getReferrers().contains(way)) {
+                    writer.println(String.format("%s is part of %s but is not in referrers", n, way));
+                }
+            }
+        }
+
+        for (Relation relation:dataSet.getRelations()) {
+            for (RelationMember m:relation.getMembers()) {
+                if (!m.getMember().getReferrers().contains(relation)) {
+                    writer.println(String.format("%s is part of %s but is not in referrers", m.getMember(), relation));
+                }
+            }
+        }
+    }
+
+    private void checkCompleteWaysWithIncompleteNodes() {
+        for (Way way:dataSet.getWays()) {
+            if (!way.incomplete) {
+                for (Node node:way.getNodes()) {
+                    if (node.incomplete) {
+                        writer.println(String.format("%s is complete but contains incomplete node '%s'", way, node));
+                    }
+                }
+            }
+        }
+    }
+
+    private void checkCompleteNodesWithoutCoordinates() {
+        for (Node node:dataSet.getNodes()) {
+            if (!node.incomplete && (node.getCoor() == null || node.getEastNorth() == null)) {
+                writer.println(String.format("%s is not incomplete but has null coordinates", node));
+            }
+        }
+    }
+
+    private void searchNodes() {
+        for (Node n:dataSet.getNodes()) {
+            if (!n.incomplete) {
+                LatLon c = n.getCoor();
+                BBox box = new BBox(new LatLon(c.lat() - 0.0001, c.lon() - 0.0001), new LatLon(c.lat() + 0.0001, c.lon() + 0.0001));
+                if (!dataSet.searchNodes(box).contains(n)) {
+                    writer.println(String.format("%s not found using Dataset.searchNodes()", n));
+                }
+            }
+        }
+    }
+
+    private void searchWays() {
+        for (Way w:dataSet.getWays()) {
+            if (!w.incomplete && !dataSet.searchWays(w.getBBox()).contains(w)) {
+                writer.println(String.format("%s not found using Dataset.searchWays()", w));
+            }
+        }
+    }
+
+    public void runTest() {
+        checkReferrers();
+        checkCompleteWaysWithIncompleteNodes();
+        checkCompleteNodesWithoutCoordinates();
+        searchNodes();
+        searchWays();
+    }
+
+    public static String runTests(DataSet dataSet) {
+        StringWriter writer = new StringWriter();
+        new DatasetConsistencyTest(dataSet, writer).runTest();
+        return writer.toString();
+    }
+
+}
Index: /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 2499)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 2500)
@@ -34,5 +34,7 @@
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.JSeparator;
+import javax.swing.JTextArea;
 
 import org.openstreetmap.josm.Main;
@@ -51,4 +53,5 @@
 import org.openstreetmap.josm.data.osm.DataSetMerger;
 import org.openstreetmap.josm.data.osm.DataSource;
+import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -232,6 +235,6 @@
 
             // paint remainder
-            ((Graphics2D)g).setPaint(hatched);
-            ((Graphics2D)g).fill(a);
+            g.setPaint(hatched);
+            g.fill(a);
         }
 
@@ -536,4 +539,5 @@
                 new JSeparator(),
                 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
+                new JMenuItem(new ConsistencyTestAction()),
                 new JSeparator(),
                 new JMenuItem(new LayerListPopup.InfoAction(this))};
@@ -550,4 +554,5 @@
                 new JSeparator(),
                 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
+                new JMenuItem(new ConsistencyTestAction()),
                 new JSeparator(),
                 new JMenuItem(new LayerListPopup.InfoAction(this))};
@@ -614,5 +619,4 @@
                 wpt.attr.put("name", name);
             }
-            ;
         }
         return gpxData;
@@ -714,3 +718,27 @@
         // keep requiresSaveToDisk unchanged
     }
+
+    private class ConsistencyTestAction extends AbstractAction {
+
+        public ConsistencyTestAction() {
+            super(tr("Dataset consistency test"));
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            String result = DatasetConsistencyTest.runTests(data);
+            if (result.length() == 0) {
+                JOptionPane.showMessageDialog(Main.parent, tr("No problems found"));
+            } else {
+                JPanel p = new JPanel(new GridBagLayout());
+                p.add(new JLabel(tr("Following problems found:")), GBC.eol());
+                JTextArea info = new JTextArea(result, 20, 60);
+                info.setCaretPosition(0);
+                info.setEditable(false);
+                p.add(new JScrollPane(info), GBC.eop());
+
+                JOptionPane.showMessageDialog(Main.parent, p, tr("Warning"), JOptionPane.WARNING_MESSAGE);
+            }
+        }
+
+    }
 }
