diff --git a/core/src/main/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbe.java b/core/src/main/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbe.java index 1cffd71cf..fd3d75c52 100644 --- a/core/src/main/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbe.java +++ b/core/src/main/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbe.java @@ -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 repositoryName = context.getRepositoryName(plugin.getScm()); diff --git a/core/src/test/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbeTest.java b/core/src/test/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbeTest.java index a3459ad6d..0b49acbcc 100644 --- a/core/src/test/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbeTest.java +++ b/core/src/test/java/io/jenkins/pluginhealth/scoring/probes/SpotBugsProbeTest.java @@ -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; + } + + } }