diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-02-23 11:12:44 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-02-23 11:12:44 +0100 |
commit | 3c5fec7277657389960231c8ee650256028a1d7a (patch) | |
tree | 07e8139b30dc7f258837cfb41f23eed6ae8d1806 /sonar-duplications | |
parent | 7efdaa4a6e4f2ce8cbcc024e74407ccb13a413d3 (diff) | |
download | sonarqube-3c5fec7277657389960231c8ee650256028a1d7a.tar.gz sonarqube-3c5fec7277657389960231c8ee650256028a1d7a.zip |
Add missing null check on equals
Diffstat (limited to 'sonar-duplications')
5 files changed, 17 insertions, 9 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java index 51ecbe54294..e92398b26f5 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/TextSet.java @@ -91,7 +91,7 @@ public final class TextSet extends AbstractText { @Override public boolean equals(Object obj) { - return (this.getClass() == obj.getClass()) && (((Terminator) obj).stringNumber == stringNumber); + return obj != null && this.getClass() == obj.getClass() && (((Terminator) obj).stringNumber == stringNumber); } @Override diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java index b840c2f55f0..818e018d4bb 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneGroup.java @@ -23,6 +23,8 @@ import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import javax.annotation.Nullable; + import java.util.ArrayList; import java.util.List; @@ -134,8 +136,8 @@ public class CloneGroup { * Two groups are equal, if they have same length, same origins and contain same parts in same order. */ @Override - public boolean equals(Object object) { - if (this.getClass() != object.getClass()) { + public boolean equals(@Nullable Object object) { + if (object == null || this.getClass() != object.getClass()) { return false; } CloneGroup another = (CloneGroup) object; diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java index 630f52c1350..0130f167197 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java @@ -21,6 +21,8 @@ package org.sonar.duplications.index; import org.sonar.duplications.CodeFragment; +import javax.annotation.Nullable; + public class ClonePart implements CodeFragment { private final String resourceId; @@ -63,8 +65,8 @@ public class ClonePart implements CodeFragment { } @Override - public boolean equals(Object obj) { - if (this.getClass() == obj.getClass()) { + public boolean equals(@Nullable Object obj) { + if (obj != null && this.getClass() == obj.getClass()) { ClonePart another = (ClonePart) obj; return another.resourceId.equals(resourceId) && another.startLine == startLine diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java b/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java index dc1c8ac402d..f698e61805b 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java @@ -22,6 +22,8 @@ package org.sonar.duplications.statement; import org.sonar.duplications.CodeFragment; import org.sonar.duplications.token.Token; +import javax.annotation.Nullable; + import java.util.List; public class Statement implements CodeFragment { @@ -81,8 +83,8 @@ public class Statement implements CodeFragment { } @Override - public boolean equals(Object obj) { - if (this.getClass() != obj.getClass()) { + public boolean equals(@Nullable Object obj) { + if (obj == null || this.getClass() != obj.getClass()) { return false; } Statement other = (Statement) obj; diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/token/Token.java b/sonar-duplications/src/main/java/org/sonar/duplications/token/Token.java index c1c374e7f52..e738ebc404e 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/token/Token.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/token/Token.java @@ -19,6 +19,8 @@ */ package org.sonar.duplications.token; +import javax.annotation.Nullable; + public class Token { private final int line; @@ -49,8 +51,8 @@ public class Token { } @Override - public boolean equals(Object object) { - if (this.getClass() == object.getClass()) { + public boolean equals(@Nullable Object object) { + if (object != null && this.getClass() == object.getClass()) { Token anotherToken = (Token) object; return anotherToken.line == line && anotherToken.column == column && anotherToken.value.equals(value); } |