Skip to content

Commit

Permalink
NPE in SpotBugsProbe when plugin is not part of UpdateCenter (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecharp authored Mar 24, 2023
1 parent ed4c88d commit 95ad433
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ protected ProbeResult doApply(Plugin plugin, ProbeContext context) {

final io.jenkins.pluginhealth.scoring.model.updatecenter.Plugin ucPlugin =
context.getUpdateCenter().plugins().get(plugin.getName());
if (ucPlugin == null) {
return ProbeResult.error(key(), "This plugin is no longer in the update-center");
}
final String defaultBranch = ucPlugin.defaultBranch();
try {
final Optional<String> repositoryName = context.getRepositoryName(plugin.getScm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,32 @@ pluginName, new VersionNumber("1.0"), scmLink, ZonedDateTime.now(), List.of(), 0
.comparingOnlyFields("id", "status", "message")
.isEqualTo(ProbeResult.failure(SpotBugsProbe.KEY, "SpotBugs not found in build configuration"));
}

@Test
void shouldNotThrowExceptionWhenPluginRemovedFromUpdateCenter() {
final Plugin plugin = mock(Plugin.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getName()).thenReturn("mailer");
when(plugin.getDetails()).thenReturn(Map.of(
JenkinsfileProbe.KEY, ProbeResult.success(JenkinsfileProbe.KEY, "")
));
when(ctx.getUpdateCenter()).thenReturn(new UpdateCenter(
Map.of(),
Map.of(),
List.of()
));

final SpotBugsProbe probe = new SpotBugsProbe();
try {
final ProbeResult result = probe.apply(plugin, ctx);
assertThat(result)
.usingRecursiveComparison()
.comparingOnlyFields("id", "status", "message")
.isEqualTo(ProbeResult.error(SpotBugsProbe.KEY, "This plugin is no longer in the update-center"));
} catch (NullPointerException ex) {
assert false;
}

}
}

0 comments on commit 95ad433

Please sign in to comment.