1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

[225996] Sort the output of -thread-list-ids must sort strings as integers, to make sure a thread with id "10" will follow thread "9" and not thread "1"

This commit is contained in:
Marc Khouzam 2010-02-26 18:18:05 +00:00
parent 1908d66ca6
commit dc066c0195

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.dsf.mi.service.command.output;
import java.util.Arrays;
import java.util.Comparator;
/**
* GDB/MI thread list parsing.
@ -50,7 +51,28 @@ public class MIThreadListIdsInfo extends MIInfo {
if (strThreadIds == null) {
parse();
// Make sure the threads are in order for the debug view
Arrays.sort(strThreadIds);
// We need our own comparator to treat these strings as integers.
Arrays.sort(strThreadIds,
new Comparator<String>() {
public int compare(String o1, String o2) {
int threadInt1;
int threadInt2;
try {
threadInt1 = Integer.parseInt(o1);
} catch (NumberFormatException e) {
return 1;
}
try {
threadInt2 = Integer.parseInt(o2);
} catch (NumberFormatException e) {
return -1;
}
return threadInt1 - threadInt2;
}
});
}
return strThreadIds;
}