Skip to content

Commit 56b9f1c

Browse files
committed
Fixed NPE when currently selected platform is no more installed.
BaseNoGui.getTargetBoard() now handles null TargetBoard. Removed unused method Base.getTargetBoard()
1 parent ec67b0d commit 56b9f1c

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

app/src/processing/app/Base.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,10 @@ public void onBoardOrPortChange() {
10771077
}
10781078

10791079
public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception {
1080+
// If there are no platforms installed skip menu creation
1081+
if (BaseNoGui.packages.size() == 0)
1082+
return;
1083+
10801084
JMenu boardsMenu = getBoardCustomMenu();
10811085

10821086
boolean first = true;
@@ -1698,11 +1702,6 @@ static public PreferencesMap getBoardPreferences() {
16981702
return BaseNoGui.getBoardPreferences();
16991703
}
17001704

1701-
public static TargetBoard getTargetBoard() {
1702-
String boardId = Preferences.get("board");
1703-
return getTargetPlatform().getBoard(boardId);
1704-
}
1705-
17061705
static public File getPortableFolder() {
17071706
return BaseNoGui.getPortableFolder();
17081707
}

app/src/processing/app/EditorLineStatus.java

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2-
31
/*
42
Part of the Processing project - http://processing.org
53
@@ -23,18 +21,23 @@
2321
package processing.app;
2422

2523
import processing.app.helpers.OSUtils;
26-
import processing.app.syntax.*;
2724

28-
import java.awt.*;
25+
import java.awt.Color;
26+
import java.awt.Dimension;
27+
import java.awt.Font;
28+
import java.awt.Graphics;
29+
import java.awt.Image;
2930
import java.awt.geom.Rectangle2D;
30-
import java.util.Map;
3131

32-
import javax.swing.*;
32+
import javax.swing.JComponent;
3333

34+
import processing.app.helpers.PreferencesMap;
35+
import processing.app.syntax.JEditTextArea;
3436

3537
/**
3638
* Li'l status bar fella that shows the line number.
3739
*/
40+
@SuppressWarnings("serial")
3841
public class EditorLineStatus extends JComponent {
3942
JEditTextArea textarea;
4043
int start = -1, stop;
@@ -52,7 +55,6 @@ public class EditorLineStatus extends JComponent {
5255
String name = "";
5356
String serialport = "";
5457

55-
5658
public EditorLineStatus(JEditTextArea textarea) {
5759
this.textarea = textarea;
5860
textarea.editorLineStatus = this;
@@ -70,7 +72,6 @@ public EditorLineStatus(JEditTextArea textarea) {
7072
//linestatus.color = #FFFFFF
7173
}
7274

73-
7475
public void set(int newStart, int newStop) {
7576
if ((newStart == start) && (newStop == stop)) return;
7677

@@ -93,11 +94,10 @@ public void set(int newStart, int newStop) {
9394
repaint();
9495
}
9596

96-
9797
public void paintComponent(Graphics g) {
98-
if (name=="" && serialport=="") {
99-
Map<String, String> boardPreferences = Base.getBoardPreferences();
100-
if (boardPreferences!=null)
98+
if (name == "" && serialport == "") {
99+
PreferencesMap boardPreferences = Base.getBoardPreferences();
100+
if (boardPreferences != null)
101101
setBoardName(boardPreferences.get("name"));
102102
else
103103
setBoardName("-");
@@ -124,8 +124,13 @@ public void paintComponent(Graphics g) {
124124
}
125125
}
126126

127-
public void setBoardName(String name) { this.name = name; }
128-
public void setSerialPort(String serialport) { this.serialport = serialport; }
127+
public void setBoardName(String name) {
128+
this.name = name;
129+
}
130+
131+
public void setSerialPort(String serialport) {
132+
this.serialport = serialport;
133+
}
129134

130135
public Dimension getPreferredSize() {
131136
return new Dimension(300, high);

arduino-core/src/processing/app/BaseNoGui.java

+21-17
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ static public File getBuildFolder() {
152152

153153
static public PreferencesMap getBoardPreferences() {
154154
TargetBoard board = getTargetBoard();
155+
if (board == null)
156+
return null;
155157

156158
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
157159
for (String menuId : board.getMenuIds()) {
@@ -343,8 +345,11 @@ static public String getSketchbookPath() {
343345
}
344346

345347
public static TargetBoard getTargetBoard() {
348+
TargetPlatform targetPlatform = getTargetPlatform();
349+
if (targetPlatform == null)
350+
return null;
346351
String boardId = PreferencesData.get("board");
347-
return getTargetPlatform().getBoard(boardId);
352+
return targetPlatform.getBoard(boardId);
348353
}
349354

350355
/**
@@ -669,28 +674,27 @@ static public void main(String args[]) throws Exception {
669674
}
670675

671676
static public void onBoardOrPortChange() {
672-
TargetPlatform targetPlatform = getTargetPlatform();
673-
if (targetPlatform == null)
674-
return;
675-
676-
// Calculate paths for libraries and examples
677677
examplesFolder = getContentFile("examples");
678678
toolsFolder = getContentFile("tools");
679-
680-
File platformFolder = targetPlatform.getFolder();
681679
librariesFolders = new ArrayList<File>();
682680
librariesFolders.add(getContentFile("libraries"));
683-
String core = getBoardPreferences().get("build.core");
684-
if (core.contains(":")) {
685-
String referencedCore = core.split(":")[0];
686-
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId());
687-
if (referencedPlatform != null) {
688-
File referencedPlatformFolder = referencedPlatform.getFolder();
689-
librariesFolders.add(new File(referencedPlatformFolder, "libraries"));
681+
682+
// Add library folder for the current selected platform
683+
TargetPlatform targetPlatform = getTargetPlatform();
684+
if (targetPlatform != null) {
685+
String core = getBoardPreferences().get("build.core");
686+
if (core.contains(":")) {
687+
String referencedCore = core.split(":")[0];
688+
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId());
689+
if (referencedPlatform != null) {
690+
File referencedPlatformFolder = referencedPlatform.getFolder();
691+
librariesFolders.add(new File(referencedPlatformFolder, "libraries"));
692+
}
690693
}
694+
File platformFolder = targetPlatform.getFolder();
695+
librariesFolders.add(new File(platformFolder, "libraries"));
696+
librariesFolders.add(getSketchbookLibrariesFolder());
691697
}
692-
librariesFolders.add(new File(platformFolder, "libraries"));
693-
librariesFolders.add(getSketchbookLibrariesFolder());
694698

695699
// Scan for libraries in each library folder.
696700
// Libraries located in the latest folders on the list can override

0 commit comments

Comments
 (0)