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
Loading
Please register or sign in to comment