Index: /trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java	(revision 2440)
+++ /trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java	(revision 2441)
@@ -361,10 +361,6 @@
         private List<T> search_contents(BBox search_bbox)
         {
-            String size = "null";
-            if (content != null) {
-                size = ""+content.size();
-            }
-            if (debug) {
-                out("searching contents (size: "+size+") for " + search_bbox);
+            if (debug) {
+                out("searching contents (size: " + content == null?"<null>":content.size() + ") for " + search_bbox);
             }
             /*
@@ -441,7 +437,5 @@
         boolean hasContent()
         {
-            if (content == null)
-                return false;
-            return true;
+            return content != null;
         }
         QBLevel nextSibling()
@@ -469,6 +463,7 @@
             QBLevel ret = null;
             for (QBLevel child : this.children) {
-                if (child == null)
+                if (child == null) {
                     continue;
+                }
                 ret = child;
                 break;
@@ -494,6 +489,7 @@
                     out("["+next.level+"] next node ("+next+") is a branch (content: "+next.hasContent()+"), moving down...");
                 }
-                if (child == null)
+                if (child == null) {
                     abort("branch node had no children");
+                }
                 next = child;
             }
@@ -1105,5 +1101,5 @@
     {
         BBox bbox = new BBox(point.lon() - radius, point.lat() - radius,
-                             point.lon() + radius, point.lat() + radius);
+                point.lon() + radius, point.lat() + radius);
         if (debug) {
             out("search bbox before sanity: " +  bbox);
@@ -1169,11 +1165,15 @@
             search_cache = root;
         }
+
+        // Save parent because search_cache might change during search call
+        QBLevel tmp = search_cache.parent;
+
         ret = search_cache.search(search_bbox);
         if (ret == null) {
             ret = new ArrayList<T>();
         }
+
         // A way that spans this bucket may be stored in one
         // of the nodes which is a parent of the search cache
-        QBLevel tmp = search_cache.parent;
         while (tmp != null) {
             List<T> content_result = tmp.search_contents(search_bbox);
@@ -1188,3 +1188,32 @@
         return ret;
     }
+
+    public void printTree() {
+        printTreeRecursive(root, 0);
+    }
+
+    private void printTreeRecursive(QBLevel level, int indent) {
+        if (level == null) {
+            printIndented(indent, "<empty child>");
+            return;
+        }
+        printIndented(indent, level);
+        if (level.hasContent()) {
+            for (T o:level.content) {
+                printIndented(indent, o);
+            }
+        }
+        if (level.children != null) {
+            for (QBLevel child:level.children) {
+                printTreeRecursive(child, indent + 2);
+            }
+        }
+    }
+
+    private void printIndented(int indent, Object msg) {
+        for (int i=0; i<indent; i++) {
+            System.out.print(' ');
+        }
+        System.out.println(msg);
+    }
 }
