diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2019-09-04 11:22:51 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-09-18 09:51:47 +0200 |
commit | 541199e925328f61eb773430686cd4e26f056273 (patch) | |
tree | 4adfd6c31d05194650d7ef0acc59f742a09e22a9 /sonar-core | |
parent | 2be53fd8bc0bff878bd4c7daebbca61720aee9c2 (diff) | |
download | sonarqube-541199e925328f61eb773430686cd4e26f056273.tar.gz sonarqube-541199e925328f61eb773430686cd4e26f056273.zip |
SONAR-12449 fix code move issue tracking missing some random issues
an initial piece of code of code move heuristic would index issues by line in a MultiMap
issues are DefaultIssue objects which hashCode method is based solely on DefaultIssue's key field
Multimap implementation used in code move was Set based
unfortunately, at this point in time, no DefaultIssue instance have a key set yet
which implies that all of them have the same hashcode
which implies when stored in the MultiMap for the same key, only one DefaultIssue instance was stored (the first added, which is unpredictable)
this change make code move heuristic use List based Multimaps which do not use DefaultIssue's hashcode
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java index 20b78655d1c..c1cb3fb88e9 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java @@ -19,7 +19,7 @@ */ package org.sonar.core.issue.tracking; -import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import java.util.Collection; @@ -140,7 +140,10 @@ class BlockRecognizer<RAW extends Trackable, BASE extends Trackable> { } private static <T extends Trackable> Multimap<Integer, T> groupByLine(Stream<T> trackables, BlockHashSequence hashSequence) { - Multimap<Integer, T> result = LinkedHashMultimap.create(); + // must use a MultiMap implementation which is not based on a Set collection because when T is a DefaultIssue + // its hashcode method returns the same value for all instances because it is based only on the DefaultIssue's + // key field which is not yet set when we do Issue Tracking + Multimap<Integer, T> result = ArrayListMultimap.create(); trackables.forEach(trackable -> { Integer line = trackable.getLine(); if (hashSequence.hasLine(line)) { |