Skip to content

Commit 237b0c7

Browse files
authored
Fix NPE on skipped turns
1 parent 46822e7 commit 237b0c7

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

robocode.host/src/main/java/net/sf/robocode/host/security/RobotThreadManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ public void start(IThreadManager threadManager) {
9494
*/
9595
public boolean waitForStop() {
9696
boolean isAlive = false;
97-
98-
if (runThread != null && runThread.isAlive()) {
99-
runThread.interrupt();
100-
waitForStop(runThread);
101-
isAlive = runThread.isAlive();
97+
Thread thr = runThread; // forceStop() can set to null concurrently
98+
if (thr != null && thr.isAlive()) {
99+
thr.interrupt();
100+
waitForStop(thr);
101+
isAlive = thr.isAlive();
102102
}
103103

104104
Thread[] threads = new Thread[100];
@@ -108,7 +108,7 @@ public boolean waitForStop() {
108108
}
109109

110110
for (Thread thread : threads) {
111-
if (thread != null && thread != runThread && thread.isAlive()) {
111+
if (thread != null && thread != thr && thread.isAlive()) {
112112
thread.interrupt();
113113
waitForStop(thread);
114114
isAlive |= thread.isAlive();

0 commit comments

Comments
 (0)