Logger logger = LoggerFactory.getLogger(IssueTrackingDecorator.class);
logger.debug("Trying to relocate manual issue {}", oldIssue.getKee());
- Collection<Integer> newLinesWithSameHash = sourceHashHolder.getNewLinesMatching(oldIssue.getLine());
+ Integer previousLine = oldIssue.getLine();
+ if (previousLine == null) {
+ logger.debug("Cannot relocate issue at resource level");
+ return;
+ }
+
+ Collection<Integer> newLinesWithSameHash = sourceHashHolder.getNewLinesMatching(previousLine);
logger.debug("Found the following lines with same hash: {}", newLinesWithSameHash);
- if (newLinesWithSameHash.size() == 0) {
- if (oldIssue.getLine() > sourceHashHolder.getHashedSource().length()) {
- logger.debug("Old issue line {} is out of new source, closing and removing line number", oldIssue.getLine());
+ if (newLinesWithSameHash.isEmpty()) {
+ if (previousLine > sourceHashHolder.getHashedSource().length()) {
+ logger.debug("Old issue line {} is out of new source, closing and removing line number", previousLine);
newIssue.setLine(null);
updater.setStatus(newIssue, Issue.STATUS_CLOSED, changeContext);
updater.setResolution(newIssue, Issue.RESOLUTION_REMOVED, changeContext);
- updater.setPastLine(newIssue, oldIssue.getLine());
+ updater.setPastLine(newIssue, previousLine);
updater.setPastMessage(newIssue, oldIssue.getMessage(), changeContext);
updater.setPastEffortToFix(newIssue, oldIssue.getEffortToFix(), changeContext);
}
logger.debug("Relocating issue to line {}", newLine);
newIssue.setLine(newLine);
- updater.setPastLine(newIssue, oldIssue.getLine());
+ updater.setPastLine(newIssue, previousLine);
updater.setPastMessage(newIssue, oldIssue.getMessage(), changeContext);
updater.setPastEffortToFix(newIssue, oldIssue.getEffortToFix(), changeContext);
}
Multimap<Integer, Integer> linesByHash = LinkedHashMultimap.create();
for (int i = 0; i < size; i++) {
hashes[i] = cmp.hash(base, i);
- linesByHash.put(hashes[i], i + 1); // indices in array are shifted one line before
+ // indices in array are shifted one line before
+ linesByHash.put(hashes[i], i + 1);
}
return new HashedSequence<S>(base, hashes, linesByHash);
}
}
public Integer getHash(Integer line) {
- return hashes[line - 1]; // indices in array are shifted one line before
+ // indices in array are shifted one line before
+ return hashes[line - 1];
}
}
assertThat(issue.status()).isEqualTo("CLOSED");
}
+ @Test
+ public void manual_issues_should_be_untouched_if_line_is_null() throws Exception {
+ Resource file = new File("Action.java").setEffectiveKey("struts:Action.java").setId(123);
+
+ // INPUT : one issue existing during previous scan
+ IssueDto unmatchedIssue = new IssueDto().setKee("ABCDE").setReporter("freddy").setLine(null).setStatus("OPEN").setRuleKey_unit_test_only("manual", "Performance");
+ when(ruleFinder.findByKey(RuleKey.of("manual", "Performance"))).thenReturn(new Rule("manual", "Performance"));
+
+ IssueTrackingResult trackingResult = new IssueTrackingResult();
+ trackingResult.addUnmatched(unmatchedIssue);
+
+ String originalSource = "public interface Action {}";
+ when(index.getSource(file)).thenReturn(originalSource);
+ when(lastSnapshots.getSource(file)).thenReturn(originalSource);
+
+ when(tracking.track(isA(SourceHashHolder.class), anyCollection(), anyCollection())).thenReturn(trackingResult);
+
+ decorator.doDecorate(file);
+
+ verify(workflow, times(1)).doAutomaticTransition(any(DefaultIssue.class), any(IssueChangeContext.class));
+ verify(handlers, times(1)).execute(any(DefaultIssue.class), any(IssueChangeContext.class));
+
+ ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
+ verify(issueCache).put(argument.capture());
+
+ DefaultIssue issue = argument.getValue();
+ assertThat(issue.line()).isEqualTo(null);
+ assertThat(issue.key()).isEqualTo("ABCDE");
+ assertThat(issue.isNew()).isFalse();
+ assertThat(issue.isEndOfLife()).isFalse();
+ assertThat(issue.isOnDisabledRule()).isFalse();
+ assertThat(issue.status()).isEqualTo("OPEN");
+ }
+
@Test
public void manual_issues_should_be_kept_if_matching_line_not_found() throws Exception {
// "Unmatched" issues existed in previous scan but not in current one -> they have to be closed