Skip to content

Commit f807cd1

Browse files
rmp22neobuddy89
authored andcommitted
fixing app directory access
Change-Id: I480874825319e35d340fc719f8c729bc1a33ed97 Signed-off-by: Pranav Vashi <[email protected]>
1 parent 8aa11f6 commit f807cd1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/java/android/app/ContextImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,6 +3757,11 @@ private File[] ensureExternalDirsExistOrFilter(File[] dirs, boolean tryCreateInP
37573757
final File[] result = new File[dirs.length];
37583758
for (int i = 0; i < dirs.length; i++) {
37593759
File dir = dirs[i];
3760+
if (dir == null) {
3761+
// If input was null, we can't do anything
3762+
result[i] = null;
3763+
continue;
3764+
}
37603765
if (!dir.exists()) {
37613766
try {
37623767
if (!tryCreateInProcess || !dir.mkdirs()) {
@@ -3769,10 +3774,11 @@ private File[] ensureExternalDirsExistOrFilter(File[] dirs, boolean tryCreateInP
37693774
}
37703775
} catch (Exception e) {
37713776
Log.w(TAG, "Failed to ensure " + dir, e);
3772-
dir = null;
3777+
// Do not null out the dir, so we can still return the path
3778+
// effectively preventing the NPE downstream
37733779
}
37743780
}
3775-
if (dir != null && !dir.canWrite()) {
3781+
if (!dir.canWrite()) {
37763782
// Older versions of the MediaProvider mainline module had a rare early boot race
37773783
// condition where app-private dirs could be created with the wrong permissions;
37783784
// fix this up here. This check should be very fast, because dir.exists() above

0 commit comments

Comments
 (0)