Bug 551065 - [debug view] Wrong selection on breakpoints that suspend VM

When using the Debug view filter to hide system threads, and breakpoints
that suspend the JVM on hit, the Debug view sporadically shows wrong
contents. Examples are wrong selection or wrong expand state of threads.

This likely occurs due to a system thread becoming suspended and then
visible in the Debug view. Expand or select operations may then be
executing with an incorrect index, as the newly visible system thread
shifts the indices of subsequent threads.

This change adds a workaround for the problem. JDTDebugTarget will list
non-system threads first, followed by system threads. This avoids the
timing problem listed above.

Change-Id: Ie4f5c2c32a110444411b785ea758fb15f6ad7b76
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java
index bb604cc..5b55b3d 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java
@@ -676,7 +676,21 @@
 	@Override
 	public IThread[] getThreads() {
 		synchronized (fThreads) {
-			return fThreads.toArray(new IThread[0]);
+			IThread[] threads = new IThread[fThreads.size()];
+			int index = 0;
+			for (JDIThread thread : fThreads) {
+				if (!thread.isSystemThread()) {
+					threads[index] = thread;
+					++index;
+				}
+			}
+			for (JDIThread thread : fThreads) {
+				if (thread.isSystemThread()) {
+					threads[index] = thread;
+					++index;
+				}
+			}
+			return threads;
 		}
 	}