From a5feec52a66d2258fe23cd262bc54e0f58113a8b Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Fri, 27 May 2016 14:06:58 -0700 Subject: [PATCH] Fix bad locking. When synchronizing on a field, it should be final to avoid locking on different objects. Missing synchronization on use of mRunning caught by Error Prone's @GuardedBy checker. Bug: 27723540 Change-Id: I9d7c9e37f8ef5f7f49707bfdf607a6b73b9654d8 --- .../android/documentsui/services/FileOperationService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/services/FileOperationService.java b/packages/DocumentsUI/src/com/android/documentsui/services/FileOperationService.java index 871e1357dd783..5b2394e449476 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/services/FileOperationService.java +++ b/packages/DocumentsUI/src/com/android/documentsui/services/FileOperationService.java @@ -95,7 +95,7 @@ public class FileOperationService extends Service implements Job.Listener { private NotificationManager mNotificationManager; @GuardedBy("mRunning") - private Map mRunning = new HashMap<>(); + private final Map mRunning = new HashMap<>(); private int mLastServiceId; @@ -176,7 +176,9 @@ public class FileOperationService extends Service implements Job.Listener { if (DEBUG) Log.d( TAG, "Scheduling job " + job.id + " to run in " + delay + " milliseconds."); ScheduledFuture future = executor.schedule(job, delay, TimeUnit.MILLISECONDS); - mRunning.put(jobId, new JobRecord(job, future)); + synchronized (mRunning) { + mRunning.put(jobId, new JobRecord(job, future)); + } } /**