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

rebuildProgrammerMenu: Handle no current board

This can happen happen in some unlikely cases (such as when renaming a
platform in a way that breaks the "select a board when none is selected
logic").

Even though a board should always be selected, code should still handle
no selected board gracefully (rather than raising a NullPointerException
like this used to do).

See #10887 for the underlying issue that caused no board to be selected.
This commit is contained in:
Matthijs Kooijman 2020-11-04 23:01:45 +01:00
parent a056a5fdc7
commit 61e12d582a

View File

@ -1702,19 +1702,21 @@ public class Base {
ButtonGroup group = new ButtonGroup();
TargetBoard board = BaseNoGui.getTargetBoard();
TargetPlatform boardPlatform = board.getContainerPlatform();
TargetPlatform corePlatform = null;
if (board != null) {
TargetPlatform boardPlatform = board.getContainerPlatform();
TargetPlatform corePlatform = null;
String core = board.getPreferences().get("build.core");
if (core != null && core.contains(":")) {
String[] split = core.split(":", 2);
corePlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
String core = board.getPreferences().get("build.core");
if (core != null && core.contains(":")) {
String[] split = core.split(":", 2);
corePlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
}
addProgrammersForPlatform(boardPlatform, programmerMenus, group);
if (corePlatform != null)
addProgrammersForPlatform(corePlatform, programmerMenus, group);
}
addProgrammersForPlatform(boardPlatform, programmerMenus, group);
if (corePlatform != null)
addProgrammersForPlatform(corePlatform, programmerMenus, group);
if (programmerMenus.isEmpty()) {
JMenuItem item = new JMenuItem(tr("No programmers available for this board"));
item.setEnabled(false);