Skip to content

Commit 2d85675

Browse files
committed
Added IllegalArgumentException Trigger For null Person During Scenario Resolution
1 parent cdff6b5 commit 2d85675

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

MekHQ/src/mekhq/MekHQ.java

+28-21
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public class MekHQ implements GameListener {
108108

109109
// region Variable Declarations
110110
private static final SuitePreferences mhqPreferences = new SuitePreferences();
111-
private static final MHQOptions mhqOptions = new MHQOptions();
112-
private static final EventBus EVENT_BUS = new EventBus();
111+
private static final MHQOptions mhqOptions = new MHQOptions();
112+
private static final EventBus EVENT_BUS = new EventBus();
113113

114114
private static ObservableString selectedTheme;
115115

@@ -124,21 +124,21 @@ public class MekHQ implements GameListener {
124124
private static ObservableString financesDirectory;
125125

126126
// stuff related to MM games
127-
private Server myServer = null;
128-
private GameThread gameThread = null;
129-
private Scenario currentScenario = null;
130-
private Client client = null;
127+
private Server myServer = null;
128+
private GameThread gameThread = null;
129+
private Scenario currentScenario = null;
130+
private Client client = null;
131131

132132
// the actual campaign - this is where the good stuff is
133133
private CampaignController campaignController;
134-
private CampaignGUI campaignGUI;
134+
private CampaignGUI campaignGUI;
135135

136136
private final IconPackage iconPackage = new IconPackage();
137137

138-
private final IAutosaveService autosaveService;
138+
private final IAutosaveService autosaveService;
139139
// endregion Variable Declarations
140140
private static final SanityInputFilter sanityInputFilter = new SanityInputFilter();
141-
private static final String defaultTheme = "com.formdev.flatlaf.FlatDarculaLaf";
141+
private static final String defaultTheme = "com.formdev.flatlaf.FlatDarculaLaf";
142142

143143
public static SuitePreferences getMHQPreferences() {
144144
return mhqPreferences;
@@ -318,9 +318,9 @@ public static void main(String... args) {
318318

319319
// First, create a global default exception handler
320320
Thread.setDefaultUncaughtExceptionHandler((thread, t) -> {
321-
final String name = t.getClass().getName();
321+
final String name = t.getClass().getName();
322322
final String message = String.format(MMLoggingConstants.UNHANDLED_EXCEPTION, name);
323-
final String title = String.format(MMLoggingConstants.UNHANDLED_EXCEPTION_TITLE, name);
323+
final String title = String.format(MMLoggingConstants.UNHANDLED_EXCEPTION_TITLE, name);
324324
logger.errorDialog(t, message, title);
325325
});
326326

@@ -390,9 +390,9 @@ public void joinGame(Scenario scenario, List<Unit> meks) {
390390
return;
391391
}
392392

393-
final String playerName = joinGameDialog.getPlayerName();
393+
final String playerName = joinGameDialog.getPlayerName();
394394
final String serverAddress = joinGameDialog.getServerAddress();
395-
final int port = joinGameDialog.getPort();
395+
final int port = joinGameDialog.getPort();
396396
joinGameDialog.dispose();
397397

398398
try {
@@ -443,11 +443,11 @@ public void startHost(Scenario scenario, boolean loadSavegame, List<Unit> meks,
443443

444444
this.autosaveService.requestBeforeMissionAutosave(getCampaign());
445445

446-
final String playerName = hostDialog.getPlayerName();
447-
final String password = hostDialog.getServerPass();
448-
final int port = hostDialog.getPort();
449-
final boolean register = hostDialog.isRegister();
450-
final String metaserver = register ? hostDialog.getMetaserver() : "";
446+
final String playerName = hostDialog.getPlayerName();
447+
final String password = hostDialog.getServerPass();
448+
final int port = hostDialog.getPort();
449+
final boolean register = hostDialog.isRegister();
450+
final String metaserver = register ? hostDialog.getMetaserver() : "";
451451

452452
// Force cleanup of the current modal, since we are (possibly) about to display a new one and macOS seems to
453453
// struggle with that (see https://github.com/MegaMek/mekhq/issues/953)
@@ -583,7 +583,7 @@ public void gameVictory(PostGameResolution gve) {
583583
BattlefieldControlType battlefieldControl = template.getBattlefieldControl();
584584

585585
String controlMessage = MHQInternationalization.getText("ResolveDialog.control." +
586-
battlefieldControl.name());
586+
battlefieldControl.name());
587587

588588
victoryMessage = String.format("%s\n\n%s", controlMessage, victoryMessage);
589589
}
@@ -632,7 +632,7 @@ public void resolveScenario(Scenario selectedScenario) {
632632
BattlefieldControlType battlefieldControl = template.getBattlefieldControl();
633633

634634
String controlMessage = MHQInternationalization.getText("ResolveDialog.control." +
635-
battlefieldControl.name());
635+
battlefieldControl.name());
636636

637637
victoryMessage = String.format("%s\n\n%s", controlMessage, victoryMessage);
638638
}
@@ -763,7 +763,7 @@ public void autoResolveConcluded(AutoResolveConcludedEvent autoResolveConcludedE
763763
BattlefieldControlType battlefieldControl = template.getBattlefieldControl();
764764

765765
String controlMessage = MHQInternationalization.getText("ResolveDialog.control." +
766-
battlefieldControl.name());
766+
battlefieldControl.name());
767767

768768
victoryMessage = String.format("%s\n\n%s\n\n%s", controlMessage, victoryMessage, decisionMessage);
769769
}
@@ -787,6 +787,13 @@ public void autoResolveConcluded(AutoResolveConcludedEvent autoResolveConcludedE
787787
if (resolveDialog.wasAborted()) {
788788
for (UUID personId : tracker.getPeopleStatus().keySet()) {
789789
Person person = getCampaign().getPerson(personId);
790+
791+
if (person == null) {
792+
throw new IllegalArgumentException("Person with ID " +
793+
personId +
794+
" does not exist in the campaign");
795+
}
796+
790797
person.setHits(person.getHitsPrior());
791798
}
792799
return;

0 commit comments

Comments
 (0)