1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Fixed NPE when unknown platform/board are selected in preference

This commit is contained in:
Cristian Maglie 2012-12-18 20:30:26 +01:00
parent 69b31ba86f
commit 12ac3f3958
2 changed files with 48 additions and 28 deletions

View File

@ -970,6 +970,8 @@ public class Base {
} }
public Map<String, File> getIDELibs() { public Map<String, File> getIDELibs() {
if (libraries == null)
return new HashMap<String, File>();
Map<String, File> ideLibs = new HashMap<String, File>(libraries); Map<String, File> ideLibs = new HashMap<String, File>(libraries);
for (String lib : libraries.keySet()) { for (String lib : libraries.keySet()) {
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib))) if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
@ -979,6 +981,8 @@ public class Base {
} }
public Map<String, File> getUserLibs() { public Map<String, File> getUserLibs() {
if (libraries == null)
return new HashMap<String, File>();
Map<String, File> userLibs = new HashMap<String, File>(libraries); Map<String, File> userLibs = new HashMap<String, File>(libraries);
for (String lib : libraries.keySet()) { for (String lib : libraries.keySet()) {
if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib))) if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
@ -1002,12 +1006,14 @@ public class Base {
importMenu.add(addLibraryMenuItem); importMenu.add(addLibraryMenuItem);
// Split between user supplied libraries and IDE libraries // Split between user supplied libraries and IDE libraries
TargetPlatform targetPlatform = getTargetPlatform();
if (targetPlatform != null) {
Map<String, File> ideLibs = getIDELibs(); Map<String, File> ideLibs = getIDELibs();
Map<String, File> userLibs = getUserLibs(); Map<String, File> userLibs = getUserLibs();
try { try {
// Find the current target. Get the platform, and then select the // Find the current target. Get the platform, and then select the
// correct name and core path. // correct name and core path.
PreferencesMap prefs = getTargetPlatform().getPreferences(); PreferencesMap prefs = targetPlatform.getPreferences();
String targetname = prefs.get("name"); String targetname = prefs.get("name");
if (false) { if (false) {
@ -1032,6 +1038,7 @@ public class Base {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
public void rebuildExamplesMenu(JMenu menu) { public void rebuildExamplesMenu(JMenu menu) {
try { try {
@ -1132,11 +1139,15 @@ public class Base {
} }
public void onBoardOrPortChange() { public void onBoardOrPortChange() {
TargetPlatform targetPlatform = getTargetPlatform();
if (targetPlatform == null)
return;
// Calculate paths for libraries and examples // Calculate paths for libraries and examples
examplesFolder = getContentFile("examples"); examplesFolder = getContentFile("examples");
toolsFolder = getContentFile("tools"); toolsFolder = getContentFile("tools");
File platformFolder = getTargetPlatform().getFolder(); File platformFolder = targetPlatform.getFolder();
librariesFolders = new ArrayList<File>(); librariesFolders = new ArrayList<File>();
librariesFolders.add(getContentFile("libraries")); librariesFolders.add(getContentFile("libraries"));
librariesFolders.add(new File(platformFolder, "libraries")); librariesFolders.add(new File(platformFolder, "libraries"));
@ -1400,6 +1411,9 @@ public class Base {
*/ */
protected boolean addSketches(JMenu menu, File folder, protected boolean addSketches(JMenu menu, File folder,
final boolean replaceExisting) throws IOException { final boolean replaceExisting) throws IOException {
if (folder == null)
return false;
// skip .DS_Store files, etc (this shouldn't actually be necessary) // skip .DS_Store files, etc (this shouldn't actually be necessary)
if (!folder.isDirectory()) return false; if (!folder.isDirectory()) return false;
@ -1846,7 +1860,10 @@ public class Base {
*/ */
static public TargetPlatform getTargetPlatform(String packageName, static public TargetPlatform getTargetPlatform(String packageName,
String platformName) { String platformName) {
return packages.get(packageName).get(platformName); TargetPackage p = packages.get(packageName);
if (p == null)
return null;
return p.get(platformName);
} }
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) { static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {

View File

@ -727,7 +727,10 @@ public class Editor extends JFrame implements RunnerListener {
protected void addTools(JMenu menu, File sourceFolder) { protected void addTools(JMenu menu, File sourceFolder) {
HashMap<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>(); if (sourceFolder == null)
return;
Map<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>();
File[] folders = sourceFolder.listFiles(new FileFilter() { File[] folders = sourceFolder.listFiles(new FileFilter() {
public boolean accept(File folder) { public boolean accept(File folder) {