Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Scoppio
Copy link
Collaborator

@Scoppio Scoppio commented May 29, 2025

fix: stop npe whe a board is missing to generate board for acar

Copilot AI review requested due to automatic review settings May 29, 2025 03:49
@Scoppio Scoppio requested a review from a team as a code owner May 29, 2025 03:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to fix a NullPointerException that occurs when a board is missing by updating the logic for iterating through the boards array.

  • Replaces a traditional for-loop with an iterator-based loop over the boards vector
  • Introduces a null and empty check to skip invalid board names

while (boardsIterator.hasNext()) {
String name = boardsIterator.next();

if (name == null || name.isEmpty()) {
Copy link

Copilot AI May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping the increment of 'i' when a board name is null or empty might lead to misalignment between the iterator and the sheetBoards array indexes. Consider incrementing 'i' even when skipping an empty name or adjust the loop logic to ensure the sheetBoards array is populated correctly.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats literally what I want to do here... 🤷🏼

Copy link
Member

@psikomonkie psikomonkie May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot’s been struggling with these, it hit me with a bunch of false positives over a for loop where I used “i” the other day.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not switch to a foreach instead of the iterator?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I need the index.

@Scoppio
Copy link
Collaborator Author

Scoppio commented May 29, 2025

Related issue MegaMek/mekhq#7121

@codecov
Copy link

codecov bot commented May 29, 2025

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 30.65%. Comparing base (d6e0bf1) to head (3c0ab5c).
Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
megamek/src/megamek/server/ServerBoardHelper.java 0.00% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7167      +/-   ##
============================================
+ Coverage     30.64%   30.65%   +0.01%     
- Complexity    17128    17150      +22     
============================================
  Files          2968     2968              
  Lines        289621   289627       +6     
  Branches      50488    50489       +1     
============================================
+ Hits          88754    88797      +43     
+ Misses       194267   194219      -48     
- Partials       6600     6611      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HammerGS HammerGS merged commit f20e70b into MegaMek:master May 29, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants