Index: /trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java	(revision 17558)
+++ /trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java	(revision 17559)
@@ -455,5 +455,10 @@
     @Override
     public Object[] toArray() {
-        return this.toList().toArray();
+        // Don't call toList() -- in some cases, this can produce an infinite loop
+        // For example, ArrayList may call toArray to get the initial array. However, since we are
+        // creating a new ArrayList in toList with `this`, this creates an infinite recursion loop.
+        // So a `toArray` call becomes `toArray -> toList -> toArray -> toList -> toArray -> ...`
+        // For more information, see #20587.
+        return this.stream().toArray();
     }
 
