zentol commented on a change in pull request #8259: [FLINK-12325][metrics] Fix
bug in statsd exporter when using negative values
URL: https://github.com/apache/flink/pull/8259#discussion_r280720727
##########
File path:
flink-metrics/flink-metrics-statsd/src/main/java/org/apache/flink/metrics/statsd/StatsDReporter.java
##########
@@ -240,12 +240,6 @@ public String filterCharacters(String input) {
}
private boolean numberIsNegative(Number input) {
- try {
- return new
BigDecimal(input.toString()).compareTo(BigDecimal.ZERO) == -1;
- } catch (Exception e) {
- //not all Number's can be converted to a BigDecimal,
such as Infinity or NaN
- //in this case we just say it isn't a negative number
- return false;
- }
+ return input.doubleValue() < 0;
Review comment:
Is there a reason you went for the simple comparison instead of the
suggested `Double#compareTo`? The javadocs list a number of special cases that
are handled differently:
```
* Compares two {@code Double} objects numerically. There
* are two ways in which comparisons performed by this method
* differ from those performed by the Java language numerical
* comparison operators ({@code <, <=, ==, >=, >})
* when applied to primitive {@code double} values:
* {@code Double.NaN} is considered by this method
* to be equal to itself and greater than all other
* {@code double} values (including
* {@code Double.POSITIVE_INFINITY}).
* {@code 0.0d} is considered by this method to be greater
* than {@code -0.0d}.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services