Skip to content

Commit 9f727ac

Browse files
committed
Permissions/IO errors can cause nullpointerexception
Fixes arduino#1160 Merge remote-tracking branch 'arduino/master-issue1160'
2 parents fcbc8e9 + d007c95 commit 9f727ac

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

app/src/processing/app/Base.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,13 @@ public boolean accept(File dir, String name) {
11791179
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
11801180

11811181
ActionListener listener = new ActionListener() {
1182-
public void actionPerformed(ActionEvent e) {
1183-
activeEditor.getSketch().importLibrary(e.getActionCommand());
1182+
public void actionPerformed(ActionEvent event) {
1183+
String jarPath = event.getActionCommand();
1184+
try {
1185+
activeEditor.getSketch().importLibrary(jarPath);
1186+
} catch (IOException e) {
1187+
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
1188+
}
11841189
}
11851190
};
11861191

@@ -1217,11 +1222,15 @@ public void actionPerformed(ActionEvent e) {
12171222
// String packages[] =
12181223
// Compiler.packageListFromClassPath(libraryClassPath);
12191224
libraries.add(subfolder);
1225+
try {
12201226
String packages[] =
12211227
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
12221228
for (String pkg : packages) {
12231229
importToLibraryTable.put(pkg, subfolder);
12241230
}
1231+
} catch (IOException e) {
1232+
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
1233+
}
12251234

12261235
JMenuItem item = new JMenuItem(libraryName);
12271236
item.addActionListener(listener);

app/src/processing/app/Sketch.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ public boolean addFile(File sourceFile) {
11281128
* Add import statements to the current tab for all of packages inside
11291129
* the specified jar file.
11301130
*/
1131-
public void importLibrary(String jarPath) {
1131+
public void importLibrary(String jarPath) throws IOException {
11321132
// make sure the user didn't hide the sketch folder
11331133
ensureExistence();
11341134

app/src/processing/app/debug/Compiler.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,18 @@ static private void createFolder(File folder) throws RunnerException {
644644
* not the header files in its sub-folders, as those should be included from
645645
* within the header files at the top-level).
646646
*/
647-
static public String[] headerListFromIncludePath(String path) {
647+
static public String[] headerListFromIncludePath(String path) throws IOException {
648648
FilenameFilter onlyHFiles = new FilenameFilter() {
649649
public boolean accept(File dir, String name) {
650650
return name.endsWith(".h");
651651
}
652652
};
653-
654-
return (new File(path)).list(onlyHFiles);
653+
654+
String[] list = (new File(path)).list(onlyHFiles);
655+
if (list == null) {
656+
throw new IOException();
657+
}
658+
return list;
655659
}
656660

657661
static public ArrayList<File> findFilesInPath(String path, String extension,

0 commit comments

Comments
 (0)