Skip to content

Commit

Permalink
Merge pull request #5815 from Sleet01/Fix_5691_NPE_when_cancelling_lo…
Browse files Browse the repository at this point in the history
…ading

Fix 5691: Add safety checks to each dialog call in the load-button handling
  • Loading branch information
Sleet01 authored Jul 28, 2024
2 parents 9bdac29 + d038e37 commit 305448d
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit 305448d

Please sign in to comment.