[libcore][DexPathList] Ensure dexElements doesn't contain null entries in addDexPath

Previously it was possible for dexElements to be mid-transaction when a
class load occurs (on a separate thread). In practice this displayed itself as
CNFE and various SEGFAULTs in places of the VM that don't protect against NULL
dexElements.

In order to combat this issue, lets compute the final dexElements Array
in a local variable and then atomically set the dexElements instance
variable once the computation is complete. I applied the same patch to
suppressed exceptions for good measure.

A TODO for a follow up commit would be to introduce barriers to ensure
coherency across threads.

Test: atest ./luni/src/test/java/libcore/dalvik/system/

Bug: https://issuetracker.google.com/issues/146447053
Bug: 146533113

Change-Id: I295f20425b406d900b75e5a1bb97725fe9964128
2 files changed