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

Fixing all Assert Usages #3615

Merged

Conversation

Windchild292
Copy link
Contributor

@Windchild292 Windchild292 commented May 3, 2022

Asserts do not work properly outside of isolated builds, so this fixes all assert uses outside of the net setup (which will be in the network rework instead). This largely removes the unused calls, only moving them to actual error handling when the call should be required.

The main changes are in the Preference setup, which uses asserts as part of the core design. Otherwise, there's a lot of cleanup in otherwise untouched files because of the change from just swapping to throwing exceptions to removing the unnecessary calls during the dev process.

This requires MegaMek/megameklab#1096 and MegaMek/mekhq#3261.

To review: Whitespace differences off.

@Windchild292 Windchild292 self-assigned this May 3, 2022
@codecov
Copy link

codecov bot commented May 4, 2022

Codecov Report

Merging #3615 (65296fc) into master (bcfbf2b) will decrease coverage by 0.00%.
The diff coverage is 15.18%.

@@             Coverage Diff              @@
##             master    #3615      +/-   ##
============================================
- Coverage     23.63%   23.63%   -0.01%     
+ Complexity     4811     4807       -4     
============================================
  Files          2204     2204              
  Lines        242385   242389       +4     
  Branches      45417    45394      -23     
============================================
- Hits          57293    57292       -1     
- Misses       183628   183642      +14     
+ Partials       1464     1455       -9     
Impacted Files Coverage Δ
megamek/src/megamek/client/Client.java 5.11% <0.00%> (-0.02%) ⬇️
megamek/src/megamek/client/bot/BotClient.java 1.57% <0.00%> (+<0.01%) ⬆️
megamek/src/megamek/client/bot/TestBot.java 0.00% <0.00%> (ø)
.../src/megamek/client/bot/princess/Precognition.java 8.06% <0.00%> (+0.01%) ⬆️
...mek/src/megamek/client/ratgenerator/UnitTable.java 0.00% <ø> (ø)
...client/ui/baseComponents/AbstractButtonDialog.java 0.00% <0.00%> (ø)
...gamek/client/ui/baseComponents/AbstractDialog.java 0.00% <0.00%> (ø)
...egamek/client/ui/baseComponents/AbstractPanel.java 0.00% <ø> (ø)
...k/client/ui/baseComponents/AbstractScrollPane.java 0.00% <ø> (ø)
...ek/client/ui/baseComponents/AbstractSplitPane.java 0.00% <0.00%> (ø)
... and 62 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bcfbf2b...65296fc. Read the comment docs.

@Windchild292 Windchild292 changed the title Fixing a Bunch of Assert Uses Fixing all Assert Usages May 4, 2022
@Windchild292 Windchild292 marked this pull request as ready for review May 4, 2022 02:13
@Windchild292
Copy link
Contributor Author

This is ready for review

Copy link
Member

@NickAragua NickAragua left a comment

Choose a reason for hiding this comment

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

A couple of questions.

skinEditPanel.setupSkinEditPanel(skinSpec);
editPanel.add(skinEditPanel);
} catch (Exception ignored) {

Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean the tear out note, it was a code misread.
Otherwise... there's a potential exception that can be thrown, but in all likelihood won't. I'll be doing a full look at catches in the future, and will probably change it then.

*/
protected void setCustomPreferences(final PreferencesNode preferences) {
protected void setCustomPreferences(final PreferencesNode preferences) throws Exception {

Check notice

Code scanning / CodeQL

Useless parameter

The parameter preferences is unused.
*/
protected void setCustomPreferences(final PreferencesNode preferences) {
protected void setCustomPreferences(final PreferencesNode preferences) throws Exception {

Check notice

Code scanning / CodeQL

Useless parameter

The parameter preferences is unused.
indices[i] = Integer.parseInt(strings[i]);
}
setSelectedIndices(indices);
setSelectedIndices(Arrays.stream(strings).mapToInt(Integer::parseInt).toArray());

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException

Potential uncaught 'java.lang.NumberFormatException'.
@Windchild292 Windchild292 merged commit 3710a7d into MegaMek:master Jun 2, 2022
@Windchild292 Windchild292 deleted the dev_Windchild_AssertionCleanup branch June 2, 2022 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants