From ce409098feab4f5f5ca8168cd995775e1fa32cbb Mon Sep 17 00:00:00 2001 From: Klaudio Sinani Date: Wed, 26 Oct 2022 15:16:57 +0200 Subject: [NO-JIRA] Fix reported code smells & bugs --- .../main/java/org/sonar/duplications/detector/suffixtree/TextSet.java | 2 +- .../src/main/java/org/sonar/duplications/index/CloneGroup.java | 2 +- .../src/main/java/org/sonar/duplications/index/ClonePart.java | 2 +- .../src/main/java/org/sonar/duplications/statement/Statement.java | 2 +- .../src/main/java/org/sonar/duplications/token/Token.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'sonar-duplications/src/main/java') 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 01c1bd268ec..16764bae35b 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 @@ -89,7 +89,7 @@ public final class TextSet extends AbstractText { @Override public boolean equals(Object obj) { - return (obj instanceof Terminator) && (((Terminator) obj).stringNumber == stringNumber); + return obj != null && 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 bfc6897e0fd..402682247b2 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 @@ -131,7 +131,7 @@ public class CloneGroup { */ @Override public boolean equals(Object object) { - if (!(object instanceof CloneGroup)) { + if (object == null || 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 daae5d9ace9..204b07effc0 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 @@ -60,7 +60,7 @@ public class ClonePart { @Override public boolean equals(Object obj) { - if (obj instanceof ClonePart) { + if (obj != null && 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 bb0b6c37b40..d92aebf2de9 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 @@ -79,7 +79,7 @@ public class Statement { @Override public boolean equals(Object obj) { - if (!(obj instanceof Statement)) { + if (obj == null || 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 6f2f3d00e05..58a080588d6 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 @@ -50,7 +50,7 @@ public class Token { @Override public boolean equals(Object object) { - if (object instanceof Token) { + if (object != null && getClass() == object.getClass()) { Token anotherToken = (Token) object; return anotherToken.line == line && anotherToken.column == column && anotherToken.value.equals(value); } -- cgit v1.2.3