Fix race condition in java.security.Provider

The supportedFormats and supportedClasses arrays are supposed to
be set only once inside the hasKeyAttributes() function. This is
guarded by the volatile flag hasKeyAttributes, however there was
a race condition when multiple threads check the flag
concurrently and then reach the synchronized block. In that case
the attributes might get set multiple times, concurrent with
reads.

This change fixes this by checking again the guard flag once
inside the synchronized block.

Bug: 276503829
Test: atest CtsLibcoreOjTestCases
Change-Id: Ic544033c1e49e823564c8a05ab3df50286e4c2e0
1 file changed