Skip to content

Commit

Permalink
Add null checks for textfield texts. (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfl28 committed Nov 15, 2023
1 parent 086724c commit 41df50f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public void initiateBoundingBoxPrediction(File imageFile) {
public void onRegisterAddObjectCategoryAction() {
final String categoryName = view.getObjectCategoryInputField().getText();

if(categoryName.isBlank()) {
if(categoryName == null || categoryName.isBlank()) {
MainView.displayErrorAlert(CATEGORY_INPUT_ERROR_DIALOG_TITLE,
INVALID_CATEGORY_NAME_ERROR_DIALOG_CONTENT, stage);
view.getObjectCategoryInputField().clear();
Expand Down Expand Up @@ -562,7 +562,7 @@ public void onSelectorCellEditEvent(TableColumn.CellEditEvent<ObjectCategory, St
String newName = event.getNewValue();
String oldName = event.getOldValue();

if(oldName.equals(newName)) {
if(Objects.equals(oldName, newName)) {
// Nothing to do if the new name is the same as the current one.
return;
}
Expand All @@ -571,7 +571,7 @@ public void onSelectorCellEditEvent(TableColumn.CellEditEvent<ObjectCategory, St
final Map<String, Integer> boundingShapesPerCategoryNameMap =
model.getCategoryToAssignedBoundingShapesCountMap();

if(newName.isBlank()) {
if(newName == null || newName.isBlank()) {
MainView.displayErrorAlert(Controller.CATEGORY_INPUT_ERROR_DIALOG_TITLE,
INVALID_CATEGORY_NAME_ERROR_DIALOG_CONTENT, stage);
objectCategory.setName(oldName);
Expand All @@ -582,10 +582,14 @@ public void onSelectorCellEditEvent(TableColumn.CellEditEvent<ObjectCategory, St
objectCategory.setName(oldName);
event.getTableView().refresh();
} else {
int assignedBoundingShapesCount = boundingShapesPerCategoryNameMap.get(oldName);
boundingShapesPerCategoryNameMap.remove(oldName);
if(oldName != null) {
int assignedBoundingShapesCount = boundingShapesPerCategoryNameMap.get(oldName);
boundingShapesPerCategoryNameMap.remove(oldName);
boundingShapesPerCategoryNameMap.put(newName, assignedBoundingShapesCount);
} else {
boundingShapesPerCategoryNameMap.put(newName, 0);
}

boundingShapesPerCategoryNameMap.put(newName, assignedBoundingShapesCount);
objectCategory.setName(newName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ private void setUpInternalListeners() {
tagFlowPane.maxWidthProperty().bind(widthProperty());

tagInputField.setOnAction(event -> {
String text = tagInputField.getText();
final String text = tagInputField.getText();
// Empty or already existing tags are not added to the list of tags.
if(!text.isEmpty() && !tags.get().contains(text)) {
if(text != null && !text.isEmpty() && !tags.get().contains(text)) {
tags.get().add(text);
}
requestFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void connectToController(Controller controller) {
private boolean validateMinimumScoreControlData() {
boolean valid = true;

if(minimumScoreControl.getEditor().getText().isBlank()) {
if(minimumScoreControl.getEditor().getText() == null || minimumScoreControl.getEditor().getText().isBlank()) {
minimumScoreControl.getEditor().pseudoClassStateChanged(invalidValuePseudoClass, true);
valid = false;
} else {
Expand All @@ -276,7 +276,7 @@ private boolean validateInferenceServerData() {
private boolean validateAddressPortTextFields(TextField addressField, TextField portField) {
boolean valid = true;

if(addressField.getText().isBlank()) {
if(addressField.getText() == null || addressField.getText().isBlank()) {
addressField.pseudoClassStateChanged(invalidValuePseudoClass, true);
valid = false;
} else {
Expand Down Expand Up @@ -385,7 +385,10 @@ private void addManagementAddressRow(int row) {
private void addModelSelectionRow(int row) {
selectModelButton.disableProperty().bind(
Bindings.createBooleanBinding(
() -> managementAddressField.getText().isBlank() || managementPortField.getText().isBlank(),
() -> managementAddressField.getText() == null
|| managementAddressField.getText().isBlank()
|| managementPortField == null
|| managementPortField.getText().isBlank(),
managementAddressField.textProperty(),
managementPortField.textProperty()));

Expand Down

0 comments on commit 41df50f

Please sign in to comment.