summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2014-03-17 16:32:05 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-03-17 16:32:05 +0000
commitd88d817498327462f42e50348239eac59147f310 (patch)
tree66e31f68b9a4a10a3c6049651bc7344642a28e14 /core
parentd93e7b2424b7ab442065b0d9cecb8b72a9c5c8ed (diff)
parentbbf1861fdd2ba250354c060fe70f0ee7cbe93877 (diff)
downloadframeworks_base-d88d817498327462f42e50348239eac59147f310.zip
frameworks_base-d88d817498327462f42e50348239eac59147f310.tar.gz
frameworks_base-d88d817498327462f42e50348239eac59147f310.tar.bz2
Merge "Null pointer exception in FileRotator.java"
Diffstat (limited to 'core')
-rw-r--r--core/java/com/android/internal/util/FileRotator.java7
-rw-r--r--core/tests/coretests/src/com/android/internal/util/FileRotatorTest.java13
2 files changed, 19 insertions, 1 deletions
diff --git a/core/java/com/android/internal/util/FileRotator.java b/core/java/com/android/internal/util/FileRotator.java
index 26235f1..71550be 100644
--- a/core/java/com/android/internal/util/FileRotator.java
+++ b/core/java/com/android/internal/util/FileRotator.java
@@ -336,7 +336,12 @@ public class FileRotator {
final long deleteBefore = currentTimeMillis - mDeleteAgeMillis;
final FileInfo info = new FileInfo(mPrefix);
- for (String name : mBasePath.list()) {
+ String[] baseFiles = mBasePath.list();
+ if (baseFiles == null) {
+ return;
+ }
+
+ for (String name : baseFiles) {
if (!info.parse(name)) continue;
if (info.isActive()) {
diff --git a/core/tests/coretests/src/com/android/internal/util/FileRotatorTest.java b/core/tests/coretests/src/com/android/internal/util/FileRotatorTest.java
index 95f0e67..0e3c13a 100644
--- a/core/tests/coretests/src/com/android/internal/util/FileRotatorTest.java
+++ b/core/tests/coretests/src/com/android/internal/util/FileRotatorTest.java
@@ -43,7 +43,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
+import junit.framework.Assert;
+
import libcore.io.IoUtils;
+import libcore.io.Libcore;
/**
* Tests for {@link FileRotator}.
@@ -367,6 +370,16 @@ public class FileRotatorTest extends AndroidTestCase {
assertReadAll(rotate, "bar");
}
+ public void testFileSystemInaccessible() throws Exception {
+ File inaccessibleDir = null;
+ String dirPath = getContext().getFilesDir() + File.separator + "inaccessible";
+ inaccessibleDir = new File(dirPath);
+ final FileRotator rotate = new FileRotator(inaccessibleDir, PREFIX, SECOND_IN_MILLIS, SECOND_IN_MILLIS);
+
+ // rotate should not throw on dir not mkdir-ed (or otherwise inaccessible)
+ rotate.maybeRotate(TEST_TIME);
+ }
+
private void touch(String... names) throws IOException {
for (String name : names) {
final OutputStream out = new FileOutputStream(new File(mBasePath, name));