]> source.dussan.org Git - sonarqube.git/commitdiff
fix floating point equality
authorZipeng WU <zipeng.wu@sonarsource.com>
Tue, 8 Dec 2020 15:19:22 +0000 (16:19 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 9 Dec 2020 20:07:21 +0000 (20:07 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java
server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasureJsonWriter.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java

index c022997707411bfaa533dbaae9f5478d32c930e0..5a3a6872bcbb770e6a21e36deddeff7b53d411ae 100644 (file)
@@ -180,7 +180,7 @@ public class TrackerRawInputFactory {
       if (reportIssue.getSeverity() != Severity.UNSET_SEVERITY) {
         issue.setSeverity(reportIssue.getSeverity().name());
       }
-      if (reportIssue.getGap() != 0) {
+      if (Double.compare(reportIssue.getGap(), 0D) != 0) {
         issue.setGap(reportIssue.getGap());
       }
       DbIssues.Locations.Builder dbLocationsBuilder = DbIssues.Locations.newBuilder();
index 0481d5a85e9fb40a194cf30fa696bcb19759e957..20e03b81675f03b31df89a422f579b26bf39e370 100644 (file)
@@ -84,7 +84,7 @@ public class LiveMeasureDtoToMeasure {
     if (value == null) {
       return toNoValueMeasure(measureDto);
     }
-    return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).create(value == 1.0d, data));
+    return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).create(Double.compare(value, 1.0D) == 0, data));
   }
 
   private static Optional<Measure> toStringMeasure(LiveMeasureDto measureDto, @Nullable String data) {
index 222b60e056680308d93ebac0ffa77fd5407e039e..e8892cb996512d45b1e5bab85f1d8cf71dc9da38 100644 (file)
@@ -98,7 +98,7 @@ public class DebtRatingGrid {
     private Bounds(double lowerBound, double higherBound) {
       this.lowerBound = lowerBound;
       this.higherBound = higherBound;
-      this.isLowerBoundInclusive = lowerBound == 0;
+      this.isLowerBoundInclusive = Double.compare(lowerBound, 0D) == 0;
     }
 
     boolean match(double value) {
index 7f3635d4b45a5d0f9869f067e16d6a44075ddb1a..dc71e211e5f785ae2ed12128b834305ae6a22aa7 100644 (file)
@@ -88,7 +88,7 @@ public class CustomMeasureJsonWriter {
 
     switch (metricType) {
       case BOOL:
-        return doubleValue == 1.0d ? "true" : "false";
+        return Double.compare(doubleValue, 1.0D) == 0 ? "true" : "false";
       case INT:
       case MILLISEC:
         return String.valueOf((int) doubleValue);
index 056c3814f756242690d29ba840e86c28c3fed2ab..7b22e7ad95d9002e0c36007aec3e79af13b82b7f 100644 (file)
@@ -82,7 +82,7 @@ public class DefaultFilterableIssue implements FilterableIssue {
 
   @Override
   public Double gap() {
-    return rawIssue.getGap() != 0 ? rawIssue.getGap() : null;
+    return Double.compare(rawIssue.getGap(), 0D) != 0 ? rawIssue.getGap() : null;
   }
 
   @Override