mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +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);
|
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
ActionListener listener = new ActionListener() {
|
ActionListener listener = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
activeEditor.getSketch().importLibrary(e.getActionCommand());
|
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[] =
|
// String packages[] =
|
||||||
// Compiler.packageListFromClassPath(libraryClassPath);
|
// Compiler.packageListFromClassPath(libraryClassPath);
|
||||||
libraries.add(subfolder);
|
libraries.add(subfolder);
|
||||||
|
try {
|
||||||
String packages[] =
|
String packages[] =
|
||||||
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
|
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
|
||||||
for (String pkg : packages) {
|
for (String pkg : packages) {
|
||||||
importToLibraryTable.put(pkg, subfolder);
|
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);
|
JMenuItem item = new JMenuItem(libraryName);
|
||||||
item.addActionListener(listener);
|
item.addActionListener(listener);
|
||||||
|
@ -1128,7 +1128,7 @@ public class Sketch {
|
|||||||
* Add import statements to the current tab for all of packages inside
|
* Add import statements to the current tab for all of packages inside
|
||||||
* the specified jar file.
|
* 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
|
// make sure the user didn't hide the sketch folder
|
||||||
ensureExistence();
|
ensureExistence();
|
||||||
|
|
||||||
|
@ -644,14 +644,18 @@ public class Compiler implements MessageConsumer {
|
|||||||
* not the header files in its sub-folders, as those should be included from
|
* not the header files in its sub-folders, as those should be included from
|
||||||
* within the header files at the top-level).
|
* 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() {
|
FilenameFilter onlyHFiles = new FilenameFilter() {
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
return name.endsWith(".h");
|
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,
|
static public ArrayList<File> findFilesInPath(String path, String extension,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user