Skip to content

Commit

Permalink
commons: add null check to nanToZero method
Browse files Browse the repository at this point in the history
Motivation:

https://rb.dcache.org/r/13867/
neglected the possibility that the value could be null.

In the context of the histogram code, this can occur,
particularly at initialization.

Modification:

Check for null.

Result:

No exception.

Target: master
Request: 8.2  (update pull request)
Request: 8.1  (update pull request)
Request: 8.0  (update pull request)
Request: 7.2  (update pull request)
Pull-request:  #6980
Pull-request:  #6981
Pull-request:  #6982
Pull-request:  #6983
Requires-notes: no
Patch: https://rb.dcache.org/r/13868/
Acked-by: Paul
  • Loading branch information
alrossi authored and lemora committed Feb 2, 2023
1 parent 51c4eb3 commit 013b84e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/common/src/main/java/org/dcache/util/MathUtils.java
Expand Up @@ -78,10 +78,10 @@ public static long subWithInfinity(long a, long b) {
* convert NaN to 0.0.
*
* @param value the double result of the computation.
* @return 0.0 if the value is NaN; otherwise, the value.
* @return 0.0 if the value is NaN; otherwise, the value (including null).
*/
public static Double nanToZero(Double value) {
return Double.isNaN(value) ? 0.0 : value;
return value != null && Double.isNaN(value) ? 0.0 : value;
}

}

0 comments on commit 013b84e

Please sign in to comment.