Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5691: Add safety checks to each dialog call in the load-button handling #5815

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions megamek/src/megamek/client/ui/swing/DeploymentDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,12 @@ public void actionPerformed(ActionEvent evt) {
Messages.getString("DeploymentDisplay.loadUnitDialog.message", ce().getShortName(), ce().getUnusedString()),
choices);

// Abort here if no Entity was generated
if (other == null) {
return;
}

// Otherwise continue
if (!(other instanceof Infantry)) {
List<Integer> bayChoices = new ArrayList<>();
for (Transporter t : ce().getTransports()) {
Expand All @@ -738,6 +744,12 @@ public void actionPerformed(ActionEvent evt) {
String msg = Messages.getString("DeploymentDisplay.loadUnitBayNumberDialog.message", ce().getShortName());
String bayString = (String) JOptionPane.showInputDialog(clientgui.getFrame(), msg, title,
JOptionPane.QUESTION_MESSAGE, null, retVal, null);

// No choice made? Bug out.
if (bayString == null) {
return;
}

int bayNum = Integer.parseInt(bayString.substring(0, bayString.indexOf(" ")));
other.setTargetBay(bayNum);
// We need to update the entity here so that the server knows about our target bay
Expand All @@ -761,6 +773,12 @@ public void actionPerformed(ActionEvent evt) {
Messages.getString("MovementDisplay.loadProtoClampMountDialog.message", ce().getShortName()),
Messages.getString("MovementDisplay.loadProtoClampMountDialog.title"),
JOptionPane.QUESTION_MESSAGE, null, retVal, null);

// No choice made? Bug out.
if (bayString == null) {
return;
}

other.setTargetBay(bayString.equals(Messages.getString("MovementDisplay.loadProtoClampMountDialog.front")) ? 0 : 1);
// We need to update the entity here so that the server knows about our target bay
clientgui.getClient().sendUpdateEntity(other);
Expand Down