diff options
| author | 2014-03-17 16:39:13 +0000 | |
|---|---|---|
| committer | 2014-03-17 16:39:13 +0000 | |
| commit | da07fe64b09bbf75cf831067dfe678ed06950f8e (patch) | |
| tree | 50f2ce06a496f459cd62348b806273c57c703ac8 | |
| parent | f096ed68e1ee5810f436ca820c1eada4b1a182a5 (diff) | |
| parent | eeb36c5cfc107fe9128490e9e127c2bca2d24e28 (diff) | |
am eeb36c5c: am d88d8174: Merge "Null pointer exception in FileRotator.java"
* commit 'eeb36c5cfc107fe9128490e9e127c2bca2d24e28':
Null pointer exception in FileRotator.java
| -rw-r--r-- | core/java/com/android/internal/util/FileRotator.java | 7 | ||||
| -rw-r--r-- | core/tests/coretests/src/com/android/internal/util/FileRotatorTest.java | 13 |
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 26235f13deab..71550be1c8d7 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 95f0e67c0f7a..0e3c13a0e655 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)); |