From 61e12d582a1256cea998d368ae919710611b9d8e Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 4 Nov 2020 23:01:45 +0100 Subject: [PATCH] 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. --- app/src/processing/app/Base.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 1e4819bba34..732a8b02ed8 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1702,18 +1702,20 @@ public void rebuildProgrammerMenu() { 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"));