Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit a265014

Browse files
authored
Merge pull request #428 from jenkinsci/npe-additional-properties
Fix NPE when line number is not present in model
2 parents df1cda8 + 2166351 commit a265014

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

plugin/src/main/java/io/jenkins/plugins/coverage/targets/CoverageResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ public void addAdditionalProperty(final String propertyName, final String value)
828828
}
829829

830830
public Set<String> getAdditionalProperty(final String propertyName) {
831-
return additionalProperties.get(propertyName);
831+
return additionalProperties.getOrDefault(propertyName, Collections.emptySet());
832832
}
833833

834834
/**

plugin/src/test/java/io/jenkins/plugins/coverage/model/CoverageResultTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class CoverageResultTest extends AbstractCoverageTest {
2929
private static final CoverageElement SOURCE_FILE = CoverageElement.FILE;
3030
private static final CoverageElement CLASS_NAME = JavaCoverageReportAdapterDescriptor.CLASS;
3131

32+
@Test
33+
void shouldNeverReturnNullForSets() throws CoverageException {
34+
CoverageResult project = readReport("jacoco-codingstyle.xml");
35+
36+
assertThat(project.getAdditionalProperty("not-found")).isEmpty();
37+
}
38+
3239
@Test
3340
void shouldReadJaCoCoResult() throws CoverageException {
3441
CoverageResult project = readReport("jacoco-codingstyle.xml");

0 commit comments

Comments
 (0)