am d88d8174: Merge "Null pointer exception in FileRotator.java"

* commit 'd88d817498327462f42e50348239eac59147f310':
  Null pointer exception in FileRotator.java
This commit is contained in:
Jeff Sharkey
2014-03-17 09:36:03 -07:00
committed by Android Git Automerger
2 changed files with 19 additions and 1 deletions

View File

@ -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()) {

View File

@ -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));