Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 8b61ba28 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Fix concurrent access to Flag Cache.

A rare NPE sometimes occurs in FeatureFlagsClassicDebug. My best
hypothesis is that it occurs when one thread was attempting to read
the internal flag cache while another was adding an item to the cache.

The new code in this cl replaces the TreeMap with a ConcurrentHashMap.
In addition, it first tries to read the value out of the cache instead
of checking for a key's existence and then branching accordingly.

If the read fails, it determins what the value should be and adds it
to the cache, with no additionaly locks necessary beyond the internals
of `ConcurrentHashMap#put`. This means it is theoretically possible
for a flag to be `#put` twice if it is read from two different threads
simultaneously, but the odds of this are vanishingly small in addition
to being completely harmless.

Test: atest && manually built and run SystemUI
Fixes: 299029193
Change-Id: Iaaa7431dfdc454f6cacdb8561ae07d5fd9e44983
parent d62cfd94
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment