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 4728: Safety getBay, add unit test, turn down logging in one location #4731

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
10 changes: 10 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,14 @@
assertTrue(part.getChildParts().isEmpty());
verify(childPart0, times(1)).setParentPart(eq(null));
}

@Test
public void testTransportBayPartNameNoEntity() {
Campaign mockCampaign = mock(Campaign.class);
Unit mockUnit = mock(Unit.class);
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
int size = 1000;
TransportBayPart tbp = new TransportBayPart(size, 1, size, mockCampaign);
// Should return default name, _not_ throw NPE here
assertNotNull(tbp.getName());
}
}