Skip to content

Commit 71320e2

Browse files
authored
Fix null pointers in sendable chooser stuff (#449)
Was caused by the combobox getting de-selected and setting the selected option to null instead of the default option
1 parent c87faf2 commit 71320e2

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/data/SendableChooserData.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.Arrays;
77
import java.util.Map;
8+
import java.util.Objects;
89

910
/**
1011
* Represents data options sent by the robot that may be selected by the drivers.
@@ -32,9 +33,9 @@ public SendableChooserData(Map<String, Object> map) {
3233

3334
@SuppressWarnings("JavadocMethod")
3435
public SendableChooserData(String[] options, String defaultOption, String selectedOption) {
35-
this.options = options.clone();
36-
this.defaultOption = defaultOption;
37-
this.selectedOption = selectedOption;
36+
this.options = Objects.requireNonNull(options, "options").clone();
37+
this.defaultOption = Objects.requireNonNull(defaultOption, "defaultOption");
38+
this.selectedOption = Objects.requireNonNull(selectedOption, "selectedOption");
3839
}
3940

4041
public String[] getOptions() {

plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/ComboBoxChooserWidget.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package edu.wpi.first.shuffleboard.plugin.base.widget;
22

3+
import edu.wpi.first.shuffleboard.api.widget.ComplexAnnotatedWidget;
4+
import edu.wpi.first.shuffleboard.api.widget.Description;
5+
import edu.wpi.first.shuffleboard.api.widget.ParametrizedController;
36
import edu.wpi.first.shuffleboard.plugin.base.data.SendableChooserData;
47
import edu.wpi.first.shuffleboard.plugin.base.data.types.SendableChooserType;
58

69
import java.util.Map;
710

8-
import edu.wpi.first.shuffleboard.api.widget.ComplexAnnotatedWidget;
9-
import edu.wpi.first.shuffleboard.api.widget.Description;
10-
import edu.wpi.first.shuffleboard.api.widget.ParametrizedController;
1111
import javafx.fxml.FXML;
1212
import javafx.scene.control.ComboBox;
1313
import javafx.scene.layout.Pane;
@@ -37,7 +37,16 @@ private void initialize() {
3737
});
3838
comboBox.getSelectionModel()
3939
.selectedItemProperty()
40-
.addListener((__, oldValue, newValue) -> setData(getData().withSelectedOption(newValue)));
40+
.addListener((__, oldValue, newValue) -> {
41+
SendableChooserData currentData = getData();
42+
if (newValue == null) {
43+
String defaultOption = currentData.getDefaultOption();
44+
setData(currentData.withSelectedOption(defaultOption));
45+
comboBox.getSelectionModel().select(defaultOption);
46+
} else {
47+
setData(currentData.withSelectedOption(newValue));
48+
}
49+
});
4150
}
4251

4352
private void updateOptions(String... options) {

0 commit comments

Comments
 (0)