EA-32400 fix NPEs (File#listFiles can return null)

This commit is contained in:
Eugene Kudelevsky
2011-12-04 16:23:01 +04:00
parent 3d4db1ed55
commit 9c26b7ec9c
4 changed files with 33 additions and 18 deletions
@@ -739,8 +739,12 @@ public class AndroidCompileUtil {
throws IOException {
if (file.isDirectory()) {
for (File child : file.listFiles()) {
addFileToJar(jar, child, rootDirectory, packRClasses);
final File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
addFileToJar(jar, child, rootDirectory, packRClasses);
}
}
}
else if (file.isFile()) {
@@ -139,14 +139,18 @@ public class AndroidPrecompileTask implements CompileTask {
private static void removeAllPackages(@Nullable String sourceRootPath, @NotNull CompileContext context) {
final File sourceRoot = new File(sourceRootPath);
for (File child : sourceRoot.listFiles()) {
if (child.isDirectory() &&
child.getName() != null &&
StringUtil.isJavaIdentifier(child.getName())) {
final File[] children = sourceRoot.listFiles();
if (!FileUtil.delete(child)) {
context.addMessage(CompilerMessageCategory.ERROR, "Cannot delete file " + child.getAbsolutePath(),
null, -1, -1);
if (children != null) {
for (File child : children) {
if (child.isDirectory() &&
child.getName() != null &&
StringUtil.isJavaIdentifier(child.getName())) {
if (!FileUtil.delete(child)) {
context.addMessage(CompilerMessageCategory.ERROR, "Cannot delete file " + child.getAbsolutePath(),
null, -1, -1);
}
}
}
}
@@ -157,8 +157,12 @@ public class AndroidDxRunner {
}
if (file.isDirectory()) {
for (File child : file.listFiles()) {
collectFiles(root, child, result, visited, qNames);
final File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
collectFiles(root, child, result, visited, qNames);
}
}
}
else {
@@ -253,15 +253,18 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
AndroidUtils.runExternalTool(project, commandLine, true, null);
if (finalTempContentRoot != null) {
for (File child : finalTempContentRoot.listFiles()) {
final File[] children = finalTempContentRoot.listFiles();
if (SdkConstants.FD_SOURCES.equals(child.getName())) {
continue;
}
final File to = new File(contentRoot.getPath(), child.getName());
if (children != null) {
for (File child : children) {
if (SdkConstants.FD_SOURCES.equals(child.getName())) {
continue;
}
final File to = new File(contentRoot.getPath(), child.getName());
if (!FileUtil.moveDirWithContent(child, to)) {
LOG.error("Cannot move content from " + child.getPath() + " to " + to.getPath());
if (!FileUtil.moveDirWithContent(child, to)) {
LOG.error("Cannot move content from " + child.getPath() + " to " + to.getPath());
}
}
}