Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
potential data races in RouteselectActivity.java #10
Dear developers of grtransit,
I'm a Ph.D. student and I'm doing research on checking data races for Android apps. I found there is a data race in RouteselectActivity.java:
At line 158, the cursor "mCsr" is written in the AsyncTask (and this is the only written for "mCsr"). However, "mCsr" is read by "onListItemClick" at line 59 and 60. The order of the written and read is not guaranteed: after the "onCreate()" finishes, user may touch the items on the screen (i.e., "onListItemClick()" is invoked) and "mCsr" is read. But at this time point, the line 158 in AsyncTask may not be executed or not finish yet, because of the non-deterministic of concurrency. If so, there will be a NullPointerException at line 59.
A quick fix can be add a null checking before line 59:
A more complex fix would be using wait/notify, or latch.
What do you think?
On 02/23/2014 10:57 AM, yulin2 wrote:
Yes, sorry, I've been a bit slow getting back to you.
I agree there's definitely a problem there, as mCsr could indeed be used
Many thanks for pointing this out. Fortunately this is not much of a
I am a PhD student working on concurrency in Android apps. While examining the potential race yulin2 has pointed out, I realized that the accesses to mCsr are implicitly ordered and do not result in a real race.
onListItemClick can be triggered only after the list adapter is set and the items are visible. The list adapter is set in onPostExecute method, after the completion of the task in doInBackground. Hence, mCsr is already set when onListItemClick is executed.
I would like to get your comments on this issue.
Thanks in advance.
@burcuku I think @yulin2 was looking at a version of the code closer to https://github.com/gdmalet/grtransit/blob/871ca639ed547efbf85f821811a3bfb43c08816e/Android/app/src/main/java/net/kw/shrdlu/grtgtfs/Activities/RouteselectActivity.java .
The line numbers don't quite match up to his comments, but lines 73 and 74 do indeed use mCsr. However, I agree with your comments that the touch-listener is not set until after mCsr is set (line 206 in that version), so I don't think there is or was a problem.
This was fixed in changed anyhow in commit 11be118 -- see
I'm going to close this issue as I think we agree there is no problem. Many thanks for your input though! I appreciate people taking the time to check my work, although I must admit I work on this app in irregular bursts so can be slow to respond, so apologize for that.