Skip to content

Commit d6515c1

Browse files
authored
Fix missing index check in Polyspace parser (#1495)
1 parent f9d15d2 commit d6515c1

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/main/java/edu/hm/hafner/analysis/parser/PolyspaceParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ private Report parse(final Stream<String> lines) {
5050
while (lineIterator.hasNext()) {
5151
var line = lineIterator.next();
5252

53-
var attributes = line.split("\\t", 15 + offset);
54-
if (Strings.CI.containsAny(attributes[9], "Unreviewed", "To investigate", "To fix", "Other")) {
53+
var limit = 15 + offset;
54+
var attributes = line.split("\\t", limit);
55+
if (attributes.length >= limit && Strings.CI.containsAny(attributes[9], "Unreviewed", "To investigate", "To fix", "Other")) {
5556
builder.setFileName(attributes[8]);
5657
builder.setCategory(attributes[2]);
5758
builder.setDescription(attributes[1]);

src/test/java/edu/hm/hafner/analysis/parser/PolyspaceParserTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,47 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti
5757
}
5858

5959
@Test
60-
void polyspaceCPTest() {
60+
void shouldReadCPTestResults() {
6161
var warnings = parse("polyspace_cp.csv");
6262
assertThat(warnings).hasSize(4);
6363

64-
try (var softly = new SoftAssertions()) {
65-
softly.assertThat(warnings.get(0)).hasLineStart(30)
64+
assertThat(warnings.get(0)).hasLineStart(30)
6665
.hasFileName("D:/workspace/math.c")
6766
.hasCategory("Data flow")
6867
.hasDescription("Run-time Check")
6968
.hasMessage("Check: Unreachable code")
7069
.hasModuleName("xinitialize()")
7170
.hasColumnStart(4)
7271
.hasSeverity(Severity.WARNING_HIGH);
73-
softly.assertThat(warnings.get(1)).hasLineStart(34)
72+
assertThat(warnings.get(1)).hasLineStart(34)
7473
.hasFileName("D:/sample.h")
7574
.hasCategory("Data flow")
7675
.hasDescription("Run-time Check")
7776
.hasModuleName("method_a()")
7877
.hasColumnStart(4)
7978
.hasSeverity(Severity.WARNING_NORMAL);
80-
softly.assertThat(warnings.get(2)).hasLineStart(66)
79+
assertThat(warnings.get(2)).hasLineStart(66)
8180
.hasDescription("Run-time Check")
8281
.hasModuleName("errorCheck()")
8382
.hasColumnStart(4)
8483
.hasSeverity(Severity.WARNING_HIGH);
85-
softly.assertThat(warnings.get(3)).hasLineStart(217)
84+
assertThat(warnings.get(3)).hasLineStart(217)
8685
.hasDescription("MISRA C:2012")
8786
.hasMessage("Check: 10.1 Operands shall not be of an inappropriate essential type. Category: Required")
8887
.hasFileName("/file/SERVICE.c")
8988
.hasModuleName("a_message()")
9089
.hasColumnStart(27)
9190
.hasCategory("10 The essential type model")
9291
.hasSeverity(Severity.WARNING_NORMAL);
93-
}
92+
}
93+
94+
@Test
95+
@org.junitpioneer.jupiter.Issue("https://github.com/jenkinsci/analysis-model/issues/1490")
96+
void shouldHandleBrokenFiles() {
97+
var warnings = parseStringContent("""
98+
Header
99+
broken\tinput\tfile
100+
""");
101+
assertThat(warnings).isEmpty();
94102
}
95103
}

0 commit comments

Comments
 (0)