From 986eaa7b7628ccb1ba510999f8e191ef368f2d7a Mon Sep 17 00:00:00 2001 From: Hugo Benichi Date: Wed, 31 May 2017 15:31:59 +0900 Subject: [PATCH] Fix race condition in NsdManagerTest NsdManagerTest relies on the lastMessage variable to assert the connection of a client to the service. The asserts in test are done on a different thread, although the variable was not qualified volatile, which creates the chance to read a stale value. This patch fixes this race by marking the variable volatile. Bug: 32561414 Bug: 62044295 Test: NsdManagerTest works Change-Id: I0bc2cd8059c6ff8b78a2dda0ba8d6bc7e13ef951 --- tests/net/java/android/net/nsd/NsdManagerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/net/java/android/net/nsd/NsdManagerTest.java b/tests/net/java/android/net/nsd/NsdManagerTest.java index 063cd5dc48..adf6998086 100644 --- a/tests/net/java/android/net/nsd/NsdManagerTest.java +++ b/tests/net/java/android/net/nsd/NsdManagerTest.java @@ -333,7 +333,7 @@ public class NsdManagerTest { public static class MockServiceHandler extends Handler { public Context mContext; public AsyncChannel chan; - public Message lastMessage; + public volatile Message lastMessage; MockServiceHandler(Looper looper, Context context) { super(looper);