Skip to content

Commit a05c73b

Browse files
committed
Permissions/IO errors can cause nullpointerexception
Fixes #1160 Merge remote-tracking branch 'arduino/ide-1.5.x-issue1160' into ide-1.5.x
2 parents 739ab8c + 8dacb1e commit a05c73b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

app/src/processing/app/Base.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,9 +1197,14 @@ public void onBoardOrPortChange() {
11971197
// Populate importToLibraryTable
11981198
importToLibraryTable = new HashMap<String, File>();
11991199
for (File subfolder : libraries.values()) {
1200-
String packages[] = headerListFromIncludePath(subfolder);
1201-
for (String pkg : packages)
1202-
importToLibraryTable.put(pkg, subfolder);
1200+
try {
1201+
String packages[] = headerListFromIncludePath(subfolder);
1202+
for (String pkg : packages) {
1203+
importToLibraryTable.put(pkg, subfolder);
1204+
}
1205+
} catch (IOException e) {
1206+
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
1207+
}
12031208
}
12041209

12051210
// Update editors status bar
@@ -1548,8 +1553,13 @@ protected void addLibraries(JMenu menu, Map<String, File> libs) throws IOExcepti
15481553
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
15491554

15501555
ActionListener listener = new ActionListener() {
1551-
public void actionPerformed(ActionEvent e) {
1552-
activeEditor.getSketch().importLibrary(e.getActionCommand());
1556+
public void actionPerformed(ActionEvent event) {
1557+
String jarPath = event.getActionCommand();
1558+
try {
1559+
activeEditor.getSketch().importLibrary(jarPath);
1560+
} catch (IOException e) {
1561+
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
1562+
}
15531563
}
15541564
};
15551565

@@ -1571,8 +1581,12 @@ public void actionPerformed(ActionEvent e) {
15711581
* the header files in its sub-folders, as those should be included from
15721582
* within the header files at the top-level).
15731583
*/
1574-
static public String[] headerListFromIncludePath(File path) {
1575-
return path.list(new OnlyFilesWithExtension(".h"));
1584+
static public String[] headerListFromIncludePath(File path) throws IOException {
1585+
String[] list = path.list(new OnlyFilesWithExtension(".h"));
1586+
if (list == null) {
1587+
throw new IOException();
1588+
}
1589+
return list;
15761590
}
15771591

15781592
protected void loadHardware(File folder) {

app/src/processing/app/Sketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ public boolean addFile(File sourceFile) {
11241124
* Add import statements to the current tab for all of packages inside
11251125
* the specified jar file.
11261126
*/
1127-
public void importLibrary(String jarPath) {
1127+
public void importLibrary(String jarPath) throws IOException {
11281128
// make sure the user didn't hide the sketch folder
11291129
ensureExistence();
11301130

0 commit comments

Comments
 (0)