Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Fix string .equals() to avoid NPE #2509

Merged
merged 2 commits into from
Jan 11, 2019

Conversation

andreamlin
Copy link
Contributor

Fixes googleapis/google-cloud-java#4320.

Currently, we are calling fieldName.equals("someResource") which will throw a NPE when variable fieldName is null.
Avoid the NPE by calling .equals() on the constant string instead.

@andreamlin andreamlin requested a review from vam-google January 11, 2019 21:10
Copy link
Contributor

@vam-google vam-google left a comment

Choose a reason for hiding this comment

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

LGTM. Good fix and good practice in general (when compare to string literal call equals on the literal, not on the variable).

@codecov
Copy link

codecov bot commented Jan 11, 2019

Codecov Report

Merging #2509 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##             master   #2509      +/-   ##
===========================================
- Coverage      86.8%   86.8%   -0.01%     
+ Complexity     5388    5385       -3     
===========================================
  Files           460     460              
  Lines         21261   21255       -6     
  Branches       2315    2315              
===========================================
- Hits          18456   18450       -6     
  Misses         1974    1974              
  Partials        831     831
Impacted Files Coverage Δ Complexity Δ
...m/google/api/codegen/config/LongRunningConfig.java 46.73% <0%> (-2.75%) 9% <0%> (-2%)
.../java/com/google/api/codegen/util/ProtoParser.java 72.58% <0%> (-0.22%) 45% <0%> (-1%)

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 a7708d8...17c4e8a. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Jan 11, 2019

Codecov Report

Merging #2509 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##             master   #2509      +/-   ##
===========================================
- Coverage      86.8%   86.8%   -0.01%     
+ Complexity     5388    5385       -3     
===========================================
  Files           460     460              
  Lines         21261   21255       -6     
  Branches       2315    2315              
===========================================
- Hits          18456   18450       -6     
  Misses         1974    1974              
  Partials        831     831
Impacted Files Coverage Δ Complexity Δ
...m/google/api/codegen/config/LongRunningConfig.java 46.73% <0%> (-2.75%) 9% <0%> (-2%)
.../java/com/google/api/codegen/util/ProtoParser.java 72.58% <0%> (-0.22%) 45% <0%> (-1%)

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 a7708d8...17c4e8a. Read the comment docs.

@andreamlin andreamlin merged commit e579ac0 into googleapis:master Jan 11, 2019
@andreamlin andreamlin deleted the compute_string_equals branch January 11, 2019 21:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants