]> source.dussan.org Git - sonarqube.git/commitdiff
Fix NPE
authorEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 28 Apr 2011 13:14:29 +0000 (17:14 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 28 Apr 2011 13:14:29 +0000 (17:14 +0400)
sonar-plugin-api/src/main/java/org/sonar/api/rules/Violation.java
sonar-plugin-api/src/test/java/org/sonar/api/rules/ViolationTest.java

index 4cca0ad934bbe3295062357c74ccfc79e82d6c6a..4c3bf2e0a671e08c1fd62836a649dfe9d75377ba 100644 (file)
@@ -194,7 +194,7 @@ public class Violation {
    * @since 2.4
    */
   public Violation setCost(Double d) {
-    if (d >= 0) {
+    if (d == null || d >= 0) {
       this.cost = d;
       return this;
     } else {
index 2ba51cfbf7cc656f5fffb65e7256910780593ac6..e763b638c6319b0a169a971185df5607994f6229 100644 (file)
@@ -52,6 +52,15 @@ public class ViolationTest {
     assertThat(violation.getLineId(), is(1));
   }
 
+  @Test
+  public void testCostContract() {
+    violation.setCost(null);
+    assertThat(violation.getCost(), nullValue());
+
+    violation.setCost(1.0);
+    assertThat(violation.getCost(), is(1.0));
+  }
+
   @Test(expected = IllegalArgumentException.class)
   public void testCostContract_NaN() {
     violation.setCost(Double.NaN);