Fix a race condition

This commit is contained in:
Cameron Gutman 2014-11-16 14:57:54 -08:00
parent cd49334199
commit 7c39e5c974

View File

@ -109,8 +109,11 @@ public class ComputerManagerService extends Service {
if (runPoll(details) && !originalDetails.equals(details)) { if (runPoll(details) && !originalDetails.equals(details)) {
// Replace our thread entry with the new one // Replace our thread entry with the new one
synchronized (pollingThreads) { synchronized (pollingThreads) {
pollingThreads.remove(originalDetails); if (pollingThreads.remove(originalDetails) != null) {
pollingThreads.put(details, this); // This could have gone away in the meantime, so don't
// add it back if it has
pollingThreads.put(details, this);
}
} }
} }