Log when duplicate elements are first added to DexPathList.

Bug 77342775 involves duplicate paths appearing on a DexPathList
(used by PathClassLoader), but it's not clear whether they're
present when the DexPathList is first constructed or whether
they're added later. Further, it's not clear via which call chain
they are added.

This CL adds logging at the point where duplicate paths are first
added, including a stacktrace of the call stack. Adding additional
(non-duplicate) elements to a DexPathList that already contains
duplicates does not trigger further logging.

A helper method getElementPath() is used to extract the path
from an Element without calling Element.toString(). The code
was written (and tested) to tolerate the case of the path being
null, although this shouldn't ever happen in practice. Such
null elements are ignored for purposes of identifying duplicates.

Bug: 77342775
Test: Device boots
Test: Extracted the checkForDuplicates() logic together
      with a fake implementation of Element / getElementPath(),
      and manually checked in a small test program that it
      behaved as expected for a few test cases.
Change-Id: Ifd79bf213d25bbe6653ffdf329cc7acac42c95b5
1 file changed