From 2ac124b790a4f4b8c9a9ac96a4211218e5d7af85 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 22 Jun 2015 16:49:52 +0900 Subject: [PATCH] Revive Null check for backward compatibility. Bug: 21934529 Change-Id: I18e8f01be728e0400f3218a359b0dc9fd97fbbbd --- core/java/android/text/format/Formatter.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/java/android/text/format/Formatter.java b/core/java/android/text/format/Formatter.java index 13a959e6fcdd5..47d5c7982d0ad 100644 --- a/core/java/android/text/format/Formatter.java +++ b/core/java/android/text/format/Formatter.java @@ -16,6 +16,7 @@ package android.text.format; +import android.annotation.Nullable; import android.content.Context; import android.content.res.Resources; import android.net.NetworkUtils; @@ -52,7 +53,10 @@ public final class Formatter { * @param sizeBytes size value to be formatted, in bytes * @return formatted string with the number */ - public static String formatFileSize(Context context, long sizeBytes) { + public static String formatFileSize(@Nullable Context context, long sizeBytes) { + if (context == null) { + return ""; + } final BytesResult res = formatBytes(context.getResources(), sizeBytes, 0); return context.getString(com.android.internal.R.string.fileSizeSuffix, res.value, res.units); @@ -62,7 +66,10 @@ public final class Formatter { * Like {@link #formatFileSize}, but trying to generate shorter numbers * (showing fewer digits of precision). */ - public static String formatShortFileSize(Context context, long sizeBytes) { + public static String formatShortFileSize(@Nullable Context context, long sizeBytes) { + if (context == null) { + return ""; + } final BytesResult res = formatBytes(context.getResources(), sizeBytes, FLAG_SHORTER); return context.getString(com.android.internal.R.string.fileSizeSuffix, res.value, res.units);