commons-configuration icon indicating copy to clipboard operation
commons-configuration copied to clipboard

Guard MapConfiguration against null maps

Open pingpingy1 opened this issue 1 year ago • 6 comments

MapConfiguration has a protected property map, which is provided upon instantiation and cannot be changed later. The lack of null guards for this property leads to inevitable NPEs at an undetermined later time. This PR implements a fail-fast guard.

pingpingy1 avatar Mar 15 '24 02:03 pingpingy1

@pingpingy1 This PR does not even compile:

Error:  COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
Error:  /home/runner/work/commons-configuration/commons-configuration/src/test/java/org/apache/commons/configuration2/TestMapConfiguration.java:[161,57] reference to MapConfiguration is ambiguous
  both constructor MapConfiguration(java.util.Map<java.lang.String,?>) in org.apache.commons.configuration2.MapConfiguration and constructor MapConfiguration(java.util.Properties) in org.apache.commons.configuration2.MapConfiguration match

Run mvn by itself to run all build checks.

garydgregory avatar Mar 15 '24 12:03 garydgregory

@pingpingy1 Please address my comments.

garydgregory avatar Mar 17 '24 13:03 garydgregory

@garydgregory Sorry for the trouble. I clearly wasn't thinking straight when I made this PR. I think I corrected the test case with this commit.

pingpingy1 avatar Mar 18 '24 04:03 pingpingy1

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.08%. Comparing base (ad9eaa0) to head (98c291c). Report is 74 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #381      +/-   ##
============================================
- Coverage     89.09%   89.08%   -0.01%     
- Complexity     3536     3537       +1     
============================================
  Files           183      183              
  Lines          9635     9641       +6     
  Branches       1192     1196       +4     
============================================
+ Hits           8584     8589       +5     
+ Misses          772      771       -1     
- Partials        279      281       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Mar 18 '24 13:03 codecov-commenter

@pingpingy1 Would you please rebase on master?

garydgregory avatar Mar 18 '24 14:03 garydgregory

@garydgregory Done! PTAL

pingpingy1 avatar Mar 18 '24 22:03 pingpingy1