mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-19 13:54:23 +01:00
Permissions/IO errors can cause nullpointerexception
Fixes #1160 Merge remote-tracking branch 'arduino/master-issue1160'
This commit is contained in:
commit
bd4f20ed0a
@ -1179,8 +1179,13 @@ public class Base {
|
||||
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
activeEditor.getSketch().importLibrary(e.getActionCommand());
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String jarPath = event.getActionCommand();
|
||||
try {
|
||||
activeEditor.getSketch().importLibrary(jarPath);
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1217,11 +1222,15 @@ public class Base {
|
||||
// String packages[] =
|
||||
// Compiler.packageListFromClassPath(libraryClassPath);
|
||||
libraries.add(subfolder);
|
||||
try {
|
||||
String packages[] =
|
||||
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
|
||||
for (String pkg : packages) {
|
||||
importToLibraryTable.put(pkg, subfolder);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
|
||||
}
|
||||
|
||||
JMenuItem item = new JMenuItem(libraryName);
|
||||
item.addActionListener(listener);
|
||||
|
@ -1128,7 +1128,7 @@ public class Sketch {
|
||||
* Add import statements to the current tab for all of packages inside
|
||||
* the specified jar file.
|
||||
*/
|
||||
public void importLibrary(String jarPath) {
|
||||
public void importLibrary(String jarPath) throws IOException {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
|
@ -644,14 +644,18 @@ public class Compiler implements MessageConsumer {
|
||||
* not the header files in its sub-folders, as those should be included from
|
||||
* within the header files at the top-level).
|
||||
*/
|
||||
static public String[] headerListFromIncludePath(String path) {
|
||||
static public String[] headerListFromIncludePath(String path) throws IOException {
|
||||
FilenameFilter onlyHFiles = new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".h");
|
||||
}
|
||||
};
|
||||
|
||||
return (new File(path)).list(onlyHFiles);
|
||||
|
||||
String[] list = (new File(path)).list(onlyHFiles);
|
||||
if (list == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static public ArrayList<File> findFilesInPath(String path, String extension,
|
||||
|
Loading…
x
Reference in New Issue
Block a user