From 0ad48dc8aab4b1475a73e61fcd202f418ae13561 Mon Sep 17 00:00:00 2001 From: Tobias Thierer Date: Tue, 2 Aug 2016 16:41:11 +0100 Subject: [PATCH] Document the fact that StatFs.restat() and ctor can throw. StatFs.restat() and the StatFs constructor can throw IllegalArgumentException. This was not previously documented; not all callers took this into account, for example: http://r.android.com/251290 This CL adds documentation to those methods. It also adds comments to two of the callers. Separately from this CL, we may in addition consider adding new API StatFs.checkedRestat() and StatFs.checkedCreate() or similar that throw IOException; we cannot change the existing constructor and method since they are public. Test: Checked that "make" still completed successfully. Change-Id: I6a0b3cb7718939408937c61de7c3b000b948fa59 --- core/java/android/database/sqlite/SQLiteGlobal.java | 2 ++ core/java/android/os/StatFs.java | 7 +++++++ .../server/storage/DeviceStorageMonitorService.java | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/java/android/database/sqlite/SQLiteGlobal.java b/core/java/android/database/sqlite/SQLiteGlobal.java index 5ff199a752575..922d11b6ae65f 100644 --- a/core/java/android/database/sqlite/SQLiteGlobal.java +++ b/core/java/android/database/sqlite/SQLiteGlobal.java @@ -61,6 +61,8 @@ public final class SQLiteGlobal { public static int getDefaultPageSize() { synchronized (sLock) { if (sDefaultPageSize == 0) { + // If there is an issue accessing /data, something is so seriously + // wrong that we just let the IllegalArgumentException propagate. sDefaultPageSize = new StatFs("/data").getBlockSize(); } return SystemProperties.getInt("debug.sqlite.pagesize", sDefaultPageSize); diff --git a/core/java/android/os/StatFs.java b/core/java/android/os/StatFs.java index 13e9a15eedb63..aeffdc7847626 100644 --- a/core/java/android/os/StatFs.java +++ b/core/java/android/os/StatFs.java @@ -34,11 +34,16 @@ public class StatFs { * class. * * @param path path in the desired file system to stat. + * + * @throws IllegalArgumentException if the file system access fails */ public StatFs(String path) { mStat = doStat(path); } + /** + * @throws IllegalArgumentException if the file system access fails + */ private static StructStatVfs doStat(String path) { try { return Os.statvfs(path); @@ -51,6 +56,8 @@ public class StatFs { * Perform a restat of the file system referenced by this object. This is * the same as re-constructing the object with the same file system path, * and the new stat values are available upon return. + * + * @throws IllegalArgumentException if the file system access fails */ public void restat(String path) { mStat = doStat(path); diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java index 90c711a479414..35732a34ed259 100644 --- a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java +++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java @@ -330,7 +330,8 @@ public class DeviceStorageMonitorService extends SystemService { mLastReportedFreeMemTime = 0; mResolver = context.getContentResolver(); mIsBootImageOnDisk = isBootImageOnDisk(); - //create StatFs object + // If these constructors throw IllegalArgumentException, something + // is so seriously wrong that we just let the Exception propagate. mDataFileStats = new StatFs(DATA_PATH.getAbsolutePath()); mSystemFileStats = new StatFs(SYSTEM_PATH.getAbsolutePath()); mCacheFileStats = new StatFs(CACHE_PATH.getAbsolutePath());