Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle duplicate issues with different relative paths #1776

Merged
merged 3 commits into from
Jan 7, 2020
Merged

handle duplicate issues with different relative paths #1776

merged 3 commits into from
Jan 7, 2020

Conversation

guwirth
Copy link
Collaborator

@guwirth guwirth commented Jan 2, 2020

Some sensors are creating same issues with different relative paths. These issues were added several times to source files in the past.

This PR normalize paths before adding them to avoid this.

Sample:

  • xxx/aaa/bbb/../ddd/eee/source.cpp
  • xxx/aaa/ccc/../ddd/eee/source.cpp
  • => xxx/aaa/ddd/eee/source.cpp

close #1777


This change is Reviewable

Some sensors are creating same issues with different relative paths. These issues were added several times to source files in the past.
This PR normalize paths before adding them to avoid this.

Sample:
   xxx/aaa/bbb/../ddd/eee/source.cpp
   xxx/aaa/ccc/../ddd/eee/source.cpp
   => xxx/aaa/ddd/eee/source.cpp
@guwirth guwirth added this to the 1.3.2 milestone Jan 2, 2020
@guwirth guwirth self-assigned this Jan 2, 2020
Copy link
Contributor

@ivangalkin ivangalkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @guwirth and @jmecosta)


cxx-squid/src/main/java/org/sonar/cxx/utils/CxxReportLocation.java, line 37 at r1 (raw file):

  public CxxReportLocation(@Nullable String file, @Nullable String line, String info) {
    super();
    if (file != null) {

constructor of the class CxxReportLocation is a wrong place to implement any logic/transformation IMHO. It was designed as an analogue of NewIssueLocation (http://javadocs.sonarsource.org/6.0/apidocs/org/sonar/api/batch/sensor/issue/NewIssueLocation.html) and intends to capture the given arguments as is.

previously all path transformation and notmalizations were done in CxxIssuesReportSensor.java. Please have a look at #1653. I believe it's better to move the logic to this file, because it handles the resolution w.r.t. module's base directory.

Besides that the PR looks good to me. Path::nomalize()is ok. Just FYI: it's important NOT to use the canonical path because of #1575

@guwirth
Copy link
Collaborator Author

guwirth commented Jan 5, 2020

Hi @ivangalkin,

Thanks for your feedback.

The reason why I did it in CxxReportLocation is saveUniqueViolation. Here we check with a HashSet for duplicates of CxxReportIssue. This does not work with not normalized paths (and was in the past the reason for the duplicates). Think better would be to compare later in saveViolation after path is absolute. But this would be much slower?

Could also normalize inside of saveUniqueViolation?

Regards,

Copy link
Contributor

@Bertk Bertk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ivangalkin
Copy link
Contributor

@guwirth your explanation makes sense completely; caching of CxxReportIssue with non-normalized paths is wrong.

saveUniqueViolation

would be a better place IMHO since we don't scatter the path transforming logic across different
location. However I see that it requires rather bigger change.

So LGTM

@guwirth guwirth merged commit 7611ef8 into SonarOpenCommunity:master Jan 7, 2020
@guwirth guwirth mentioned this pull request Feb 10, 2020
@guwirth guwirth deleted the unique-issues-with-realtive-path branch February 14, 2020 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

clang-tidy creates duplicate issues with different relative paths
4 participants