Skip to content
Commit 8924b3cd authored by Tobias Thierer's avatar Tobias Thierer
Browse files

android.net.Uri: Move NOT_CACHED constant to holder class.

Commit b639ce9e (May 2019) introduced a
reference from PathPart.<init> to Uri.NOT_CACHED. If this happened before
Uri.<clinit> had first run, this led to an inconsistently constructed
Uri.EMPTY since that instance's path is PathPart.EMPTY, which at that
point would still have been null.

This issue was found in an environment where Zygote initializations and
preloaded classes had not been run, and the unit test included in this
CL already passes before the CL. This suggests that Uri.<clinit> already
ran in the correct order in Android Q and that the bug was only
observable on other platforms that do not perform this initialization.
Nonetheless, to avoid a fragile dependence on a particular
initialization order, this CL fixes the issue such that calling
Uri.Builder.path() prior to Uri.<clinit> is now safe.

Specifically, this CL moves the NOT_CACHED instance into its own holder
class. This way, accessing NOT_CACHED no longer triggers Uri.<clinit>.
This also makes an earlier comment (from 2009) obsolete which warned
that NOT_CACHED must be initialized before Uri.EMPTY.

I've made the holder class and its field package private to avoid the
overhead of a synthetic accessor method.

Note: This CL was uploaded with --no-verify to avoid complaints about
pre-existing style issues (private non-static fields whose name does
not start with "m").

Bug: 159907422
Test: atest FrameworksCoreTests:android.net.UriTest
Test: Manually checked that a corresponding change fixed the issue
      in an environment not forked from a Zygote process where
      the issue was previously observable.

Change-Id: I067a6c108aa8befd056818a8231930693f55d8cf
parent aeca778b
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