Check the isInUse with the lock held in MessageQueue
Fix a potential race condtion when the same message object is being enqueued by two threads. Bug: 150263007 Test: atest android.os.cts.MessageQueueTest Change-Id: Id79448ba8719479cbdb054f2cdd172fdcbe86d47
This commit is contained in:
@@ -550,11 +550,12 @@ public final class MessageQueue {
|
||||
if (msg.target == null) {
|
||||
throw new IllegalArgumentException("Message must have a target.");
|
||||
}
|
||||
if (msg.isInUse()) {
|
||||
throw new IllegalStateException(msg + " This message is already in use.");
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
if (msg.isInUse()) {
|
||||
throw new IllegalStateException(msg + " This message is already in use.");
|
||||
}
|
||||
|
||||
if (mQuitting) {
|
||||
IllegalStateException e = new IllegalStateException(
|
||||
msg.target + " sending message to a Handler on a dead thread");
|
||||
|
||||
Reference in New Issue
Block a user