Skip to content

Commit 32123a8

Browse files
author
Federico Fissore
committed
Fixed NPE in case of missing boardData
1 parent c287450 commit 32123a8

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import processing.app.helpers.PreferencesMap;
3939

4040
import java.util.ArrayList;
41+
import java.util.HashMap;
4142
import java.util.List;
4243
import java.util.Map;
4344

@@ -61,32 +62,38 @@ public List<BoardPort> discovery() {
6162

6263
for (String port : ports) {
6364
Map<String, Object> boardData = os.resolveDeviceAttachedTo(port, BaseNoGui.packages, devicesListOutput);
64-
TargetBoard board = (TargetBoard) boardData.get("board");
6565

6666
BoardPort boardPort = new BoardPort();
6767
boardPort.setAddress(port);
6868
boardPort.setProtocol("serial");
6969

70+
String label = port;
71+
7072
PreferencesMap prefs = new PreferencesMap();
71-
prefs.put("vid", boardData.get("vid").toString());
72-
prefs.put("pid", boardData.get("pid").toString());
73-
String warningKey = "vid." + boardData.get("vid").toString() + ".warning";
74-
String warning = board.getPreferences().get(warningKey);
75-
prefs.put("warning", warning);
7673

77-
String boardName = board.getName();
78-
String label = port;
79-
if (boardName != null) {
80-
if (warning != null) {
81-
label += " (" + boardName + " - " + _(warning) + ")";
82-
} else {
83-
label += " (" + boardName + ")";
74+
if (boardData != null) {
75+
prefs.put("vid", boardData.get("vid").toString());
76+
prefs.put("pid", boardData.get("pid").toString());
77+
78+
TargetBoard board = (TargetBoard) boardData.get("board");
79+
if (board != null) {
80+
String warningKey = "vid." + boardData.get("vid").toString() + ".warning";
81+
String warning = board.getPreferences().get(warningKey);
82+
prefs.put("warning", warning);
83+
84+
String boardName = board.getName();
85+
if (boardName != null) {
86+
if (warning != null) {
87+
label += " (" + boardName + " - " + _(warning) + ")";
88+
} else {
89+
label += " (" + boardName + ")";
90+
}
91+
}
92+
boardPort.setBoardName(boardName);
8493
}
8594
}
86-
boardPort.setBoardName(boardName);
87-
boardPort.setLabel(label);
88-
8995

96+
boardPort.setLabel(label);
9097
boardPort.setPrefs(prefs);
9198

9299
res.add(boardPort);

0 commit comments

Comments
 (0)