Skip to content

Commit

Permalink
Merge pull request #4731 from Sleet01/Fix_4728_prevents_NPE_when_load…
Browse files Browse the repository at this point in the history
…ing_nested_transported_units

Fix 4728: Safety getBay, add unit test, turn down logging in one location
  • Loading branch information
IllianiCBT authored Aug 28, 2024
2 parents 74c0558 + 2b09f20 commit e1aaf22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions MekHQ/src/mekhq/campaign/io/CampaignXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public Campaign parse() throws CampaignXmlParseException, NullEntityException {
timestamp = System.currentTimeMillis();

// Process parts...
// Note: Units must have their Entities set prior to reaching this point!
postProcessParts(retVal, version);

LogManager.getLogger().info(String.format("[Campaign Load] Parts processed in %dms",
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/parts/TransportBayPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public int getBayNumber() {
}

public Bay getBay() {
if (null != unit) {
if (null != unit && null != unit.getEntity()) {
return unit.getEntity().getBayById(bayNumber);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/personnel/enums/Profession.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public Profession getAlternateProfession(final String name) {
case "--CIVILIAN":
return CIVILIAN;
default:
LogManager.getLogger().error("Cannot get alternate profession for unknown alternative "
LogManager.getLogger().debug("Cannot get alternate profession for unknown alternative "
+ name + " returning MECHWARRIOR.");
return MECHWARRIOR;
}
Expand Down
9 changes: 9 additions & 0 deletions MekHQ/unittests/mekhq/campaign/parts/PartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,13 @@ public void childParts() {
assertTrue(part.getChildParts().isEmpty());
verify(childPart0, times(1)).setParentPart(eq(null));
}

@Test
public void testTransportBayPartNameNoEntity() {
Campaign mockCampaign = mock(Campaign.class);
int size = 1000;
TransportBayPart tbp = new TransportBayPart(size, 1, size, mockCampaign);
// Should return default name, _not_ throw NPE here
assertNotNull(tbp.getName());
}
}

0 comments on commit e1aaf22

Please sign in to comment.