Bug 518266: SWTUtils.allThreads() only supports up to 64 threads

Change-Id: Ibfeddfb906f20d83466a3c5a20e40472cd28d0fa
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
index c2510f3..d5936a8 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
@@ -250,11 +250,15 @@
 	public static Thread[] allThreads() {
 		ThreadGroup threadGroup = primaryThreadGroup();
 
-		Thread[] threads = new Thread[64];
-		int enumerate = threadGroup.enumerate(threads, true);
+		int numThreads = 0;
+		Thread[] threads = null;
+		while (threads == null || numThreads >= threads.length) {
+			threads = new Thread[Math.max(numThreads, threadGroup.activeCount()) + 8];
+			numThreads = threadGroup.enumerate(threads, true);
+		}
 
-		Thread[] result = new Thread[enumerate];
-		System.arraycopy(threads, 0, result, 0, enumerate);
+		Thread[] result = new Thread[numThreads];
+		System.arraycopy(threads, 0, result, 0, numThreads);
 
 		return result;
 	}