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

fix CppcheckParserV2; allow multiple NewIssueLocations #1436

Closed
wants to merge 6 commits into from

Conversation

ivangalkin
Copy link
Contributor

@ivangalkin ivangalkin commented Mar 22, 2018

This change is Reviewable

@ivangalkin
Copy link
Contributor Author

Dear All. Sorry for the mess with non-squashed commits. The change is ready for review. Thank you in advance!

return line;
}

public String getMsg() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be info

public class CxxReportLocation {
final String file;
final String line;
final String msg;
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be info

* Each issues in SonarQube might have multiple locations; Encapsulate its
* properties in this structure
*/
public class CxxReportLocation {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unit test for CxxReportLocation missing

@@ -267,70 +269,104 @@ public static String resolveFilename(final String baseDir, @Nullable final Strin
* @param ruleId
* @param msg
*/
public void saveUniqueViolation(SensorContext sensorContext, String ruleRepoKey,
@Nullable String file, @Nullable String line, String ruleId, String msg) {
public void saveUniqueViolation(SensorContext sensorContext, String ruleRepoKey, @Nullable String file,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would remove this function

* @param ruleId
* @param locations
*/
public void saveUniqueViolation(SensorContext sensorContext, String ruleRepoKey, String ruleId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would call always this function from sensors.

}

if (isInputValid(id, msg)) {
sensor.saveUniqueViolation(context, CxxCppCheckRuleRepository.KEY, file, line, id, msg);
if (locations.isEmpty()) {
sensor.saveUniqueViolation(context, CxxCppCheckRuleRepository.KEY, file, line, id, msg);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would try to handle this always with locations

@guwirth
Copy link
Collaborator

guwirth commented Mar 23, 2018

@ivangalkin thanks for your proposal. My main point is that I would unify the interface and would use always the version with CxxReportLocation list only.

@ivangalkin
Copy link
Contributor Author

Hello Günter and thank you for the reivew!

I will apply your comment in the nearest future. Unfortunately I found out, that CppcheckParserV2.java needs a bit more enhancement: For the issues with multiple locations the main message is not-equal to the message/info of the first location. E.g.

<error id="nullPointer" severity="warning" msg="Possible null pointer dereference: pLd" verbose="Possible null pointer dereference: pLd" cwe="476">
  <location file="file.cpp" line="598" info="Null pointer dereference"/>
  <location file="file.cpp" line="593" info="Assignment &apos;pLd=pLdFls0&apos;, assigned value is 0"/>
  <location file="file.cpp" line="569" info="Assignment &apos;pLdFls0=NULL&apos;, assigned value is 0"/>
</error>

According to my implementation the message becomes "Null pointer dereference", which differs from the previous logic and is quite misleading for the reader. The main message must still be "Possible null pointer dereference: pLd".

So there will be more commits.

Regards, Ivan

* create first-class citizen entities CxxReportIssue and CxxReportLocation (1:n)
  (CxxReportIssue::equals() allows clear distinguishing if issue was processed already)

* CppcheckParserV2: better implementation for primary and secondary locations

* CxxReportSensor: increase issues-per-module counter only once per CxxReportIssue,
                   increase issues-per-file counter only once per affected file

TODO (?): tests for CxxReportIssue and CxxReportLocation
TODO (?): use the new function CxxReportSensor::saveUniqueViolation(SensorContext, CxxReportIssue)
@ivangalkin
Copy link
Contributor Author

I applied all review comments, but had to re-submit the change as a new pull request #1447 (sorry, I misconfigured my fork).

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.

2 participants