Skip to content

Commit 6c14711

Browse files
committed
fix: avoid repeated message in the Coverity parser (refs #188)
1 parent 0a0daa0 commit 6c14711

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ dependencies {
6464
testImplementation 'junit:junit:4.13.2'
6565
testImplementation 'org.assertj:assertj-core:3.25.3'
6666
testImplementation 'uk.co.jemos.podam:podam:8.0.1.RELEASE'
67-
testImplementation 'com.approvaltests:approvaltests:23.0.0'
67+
testImplementation 'com.approvaltests:approvaltests:23.0.1'
6868
testImplementation 'com.networknt:json-schema-validator:1.4.0'
6969
}

src/main/java/se/bjurr/violations/lib/parsers/CoverityParser.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import se.bjurr.violations.lib.ViolationsLogger;
1212
import se.bjurr.violations.lib.model.SEVERITY;
1313
import se.bjurr.violations.lib.model.Violation;
14+
import se.bjurr.violations.lib.model.generated.coverity.CheckerProperty;
1415
import se.bjurr.violations.lib.model.generated.coverity.CoveritySchema;
1516
import se.bjurr.violations.lib.model.generated.coverity.Issue;
1617
import se.bjurr.violations.lib.reports.Parser;
18+
import se.bjurr.violations.lib.util.Utils;
1719

1820
public class CoverityParser implements ViolationsParser {
1921

@@ -32,10 +34,7 @@ public Set<Violation> parseReportOutput(
3234
violations.add(
3335
violationBuilder() //
3436
.setFile(issue.getMainEventFilePathname()) //
35-
.setMessage(
36-
issue.getCheckerProperties().getSubcategoryLocalEffect()
37-
+ "\n"
38-
+ issue.getCheckerProperties().getSubcategoryLocalEffect()) //
37+
.setMessage(this.getMessage(issue.getCheckerProperties())) //
3938
.setParser(Parser.COVERITY) //
4039
.setCategory(issue.getCheckerProperties().getCategory())
4140
.setRule(issue.getType() + "/" + issue.getSubtype()) //
@@ -46,6 +45,28 @@ public Set<Violation> parseReportOutput(
4645
return violations;
4746
}
4847

48+
private String getMessage(final CheckerProperty checkerProperty) {
49+
final boolean hasLongDescription =
50+
!Utils.isNullOrEmpty(checkerProperty.getSubcategoryLongDescription());
51+
final boolean hasLocalEffect =
52+
!Utils.isNullOrEmpty(checkerProperty.getSubcategoryLocalEffect());
53+
if (hasLongDescription && hasLocalEffect) {
54+
if (checkerProperty
55+
.getSubcategoryLongDescription()
56+
.contains(checkerProperty.getSubcategoryLocalEffect())) {
57+
return checkerProperty.getSubcategoryLongDescription();
58+
}
59+
return checkerProperty.getSubcategoryLongDescription()
60+
+ ".\n"
61+
+ checkerProperty.getSubcategoryLocalEffect();
62+
} else if (hasLongDescription) {
63+
return checkerProperty.getSubcategoryLongDescription();
64+
} else if (hasLocalEffect) {
65+
return checkerProperty.getSubcategoryLocalEffect();
66+
}
67+
return checkerProperty.getImpactDescription();
68+
}
69+
4970
private SEVERITY toSeverity(final String from) {
5071
if (from.equalsIgnoreCase("Medium")) {
5172
return WARN;

src/test/java/se/bjurr/violations/lib/CoverityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testThatViolationsCanBeParsed() {
3030
final Violation violation0 = new ArrayList<>(actual).get(0);
3131
assertThat(violation0.getMessage()) //
3232
.isEqualTo(
33-
"The expression's value is always zero; construct may indicate an inadvertent logic error.\nThe expression's value is always zero; construct may indicate an inadvertent logic error.");
33+
"Bitwise-and ('&amp;') operation applied to zero always produces zero.\nThe expression's value is always zero; construct may indicate an inadvertent logic error.");
3434
assertThat(violation0.getFile()) //
3535
.isEqualTo("C:/Workspace/workspace/Build_jenkins_development/somefile.cs");
3636
assertThat(violation0.getSeverity()) //

0 commit comments

Comments
 (0)