Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d8ef00c authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Fix NPE in DateFormat.is24HourFormat.

In some cases, we end up being called by code that doesn't have a valid
Context. It got away with this historically because it wasn't formatting
times (just dates), so it never went down a path that tried to query the
user's 12/24-hour preference. This patch just ensures that we don't try
to get the preference unless we actually need it.

Bug: 10339015
Change-Id: I2df466d85cdeba14dbf882498808cbad9bbb57f4
parent 82461951
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -816,9 +816,10 @@ public class DateUtils
     */
    public static Formatter formatDateRange(Context context, Formatter formatter, long startMillis,
                                            long endMillis, int flags, String timeZone) {
        // icu4c will fall back to the locale's preferred 12/24 format,
        // If we're being asked to format a time without being explicitly told whether to use
        // the 12- or 24-hour clock, icu4c will fall back to the locale's preferred 12/24 format,
        // but we want to fall back to the user's preference.
        if ((flags & (FORMAT_12HOUR | FORMAT_24HOUR)) == 0) {
        if ((flags & (FORMAT_SHOW_TIME | FORMAT_12HOUR | FORMAT_24HOUR)) == FORMAT_SHOW_TIME) {
            flags |= DateFormat.is24HourFormat(context) ? FORMAT_24HOUR : FORMAT_12HOUR;
        }