diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 62c2db364..1bd519769 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -2604,12 +2604,15 @@ public class Base { File targetDir) throws IOException { targetDir.mkdirs(); String files[] = sourceDir.list(); - for (int i = 0; i < files.length; i++) { + if (files == null) { + throw new IOException("Unable to list files from " + sourceDir); + } + for (String file : files) { // Ignore dot files (.DS_Store), dot folders (.svn) while copying - if (files[i].charAt(0) == '.') continue; + if (file.charAt(0) == '.') continue; //if (files[i].equals(".") || files[i].equals("..")) continue; - File source = new File(sourceDir, files[i]); - File target = new File(targetDir, files[i]); + File source = new File(sourceDir, file); + File target = new File(targetDir, file); if (source.isDirectory()) { //target.mkdirs(); copyDir(source, target); diff --git a/app/src/processing/app/tools/Archiver.java b/app/src/processing/app/tools/Archiver.java index c0f533023..81a60e41b 100644 --- a/app/src/processing/app/tools/Archiver.java +++ b/app/src/processing/app/tools/Archiver.java @@ -150,6 +150,9 @@ public class Archiver implements Tool { public void buildZip(File dir, String sofar, ZipOutputStream zos) throws IOException { String files[] = dir.list(); + if (files == null) { + throw new IOException("Unable to list files from " + dir); + } for (int i = 0; i < files.length; i++) { if (files[i].equals(".") || files[i].equals("..")) continue; diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 938c36768..9ae944cfe 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -956,14 +956,18 @@ public class BaseNoGui { if (!dir.exists()) return; String files[] = dir.list(); - for (int i = 0; i < files.length; i++) { - if (files[i].equals(".") || files[i].equals("..")) continue; - File dead = new File(dir, files[i]); + if (files == null) { + return; + } + + for (String file : files) { + if (file.equals(".") || file.equals("..")) continue; + File dead = new File(dir, file); if (!dead.isDirectory()) { if (!PreferencesData.getBoolean("compiler.save_build_files")) { if (!dead.delete()) { // temporarily disabled - System.err.println(I18n.format(_("Could not delete {0}"), dead)); + System.err.println(I18n.format(_("Could not delete {0}"), dead)); } } } else { diff --git a/arduino-core/src/processing/app/SketchData.java b/arduino-core/src/processing/app/SketchData.java index 36f5a8fce..677edcc80 100644 --- a/arduino-core/src/processing/app/SketchData.java +++ b/arduino-core/src/processing/app/SketchData.java @@ -95,6 +95,9 @@ public class SketchData { // get list of files in the sketch folder String list[] = folder.list(); + if (list == null) { + throw new IOException("Unable to list files from " + folder); + } // reset these because load() may be called after an // external editor event. (fix for 0099) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index e99414465..d6ecbcfd6 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -277,11 +277,13 @@ public class Compiler implements MessageConsumer { // used. Keep everything else, which might be reusable if (tempBuildFolder.exists()) { String files[] = tempBuildFolder.list(); - for (String file : files) { - if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) { - File deleteMe = new File(tempBuildFolder, file); - if (!deleteMe.delete()) { - System.err.println("Could not delete " + deleteMe); + if (files != null) { + for (String file : files) { + if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) { + File deleteMe = new File(tempBuildFolder, file); + if (!deleteMe.delete()) { + System.err.println("Could not delete " + deleteMe); + } } } }