From 86da47e8d72f275b7f6e111930dfe205cb34423f Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Fri, 27 Dec 2013 14:58:38 +0900 Subject: [PATCH] Fix possible NPE in FileUtils. Change-Id: I503f91e266c71e2370a5807d171e2254c334f7cb --- .../com/android/inputmethod/latin/utils/FileUtils.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/utils/FileUtils.java b/java/src/com/android/inputmethod/latin/utils/FileUtils.java index 22b0fbbcd..f1106a6c6 100644 --- a/java/src/com/android/inputmethod/latin/utils/FileUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/FileUtils.java @@ -25,8 +25,11 @@ import java.io.FilenameFilter; public class FileUtils { public static boolean deleteRecursively(final File path) { if (path.isDirectory()) { - for (final File child : path.listFiles()) { - deleteRecursively(child); + final File[] files = path.listFiles(); + if (files != null) { + for (final File child : files) { + deleteRecursively(child); + } } } return path.delete(); @@ -37,6 +40,9 @@ public class FileUtils { return false; } final File[] files = dir.listFiles(fileNameFilter); + if (files == null) { + return false; + } boolean hasDeletedAllFiles = true; for (final File file : files) { if (!deleteRecursively(file)) {