diff --git a/war/src/main/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationService.java b/war/src/main/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationService.java index 0f1daecaf..604da3808 100644 --- a/war/src/main/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationService.java +++ b/war/src/main/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationService.java @@ -52,11 +52,15 @@ public PluginDocumentationService(ObjectMapper objectMapper, ApplicationConfigur public Map fetchPluginDocumentationUrl() { try { - final Map foo = objectMapper.readValue(new URL(configuration.jenkins().documentationUrls()), new TypeReference<>() {}); - return foo.entrySet().stream() + final Map documentationUrlsMap = objectMapper.readValue( + new URL(configuration.jenkins().documentationUrls()), + new TypeReference<>() { + } + ); + return documentationUrlsMap.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, - e -> e.getValue().url() + e -> e.getValue() == null || e.getValue().url() == null ? "" : e.getValue().url() )); } catch (MalformedURLException e) { LOGGER.error("URL to documentation link is incorrect.", e); diff --git a/war/src/test/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationServiceTest.java b/war/src/test/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationServiceTest.java index 735fa1f18..2ffee24b5 100644 --- a/war/src/test/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationServiceTest.java +++ b/war/src/test/java/io/jenkins/pluginhealth/scoring/service/PluginDocumentationServiceTest.java @@ -59,6 +59,24 @@ void shouldBeAbleToParseAvailableFile() { .contains(entry("bar", "https://github.com/jenkinsci/bar-plugin")); } + @Test + void shouldBeAbleToParseFileWithNullValue() { + final URL url = PluginDocumentationService.class.getResource("/documentation-urls/plugin-documentation-urls-with-nulls.json"); + assertThat(url).isNotNull(); + + final ApplicationConfiguration config = new ApplicationConfiguration( + new ApplicationConfiguration.Jenkins("foo", url.toString()), + new ApplicationConfiguration.GitHub("foo", null, "bar") + ); + + final PluginDocumentationService service = new PluginDocumentationService(objectMapper, config); + final Map map = service.fetchPluginDocumentationUrl(); + + assertThat(map) + .contains(entry("foo", "https://wiki.jenkins-ci.org/display/JENKINS/foo+plugin")) + .contains(entry("bar", "https://github.com/jenkinsci/bar-plugin")); + } + @Test void shouldSurviveIncorrectlyConfiguredDocumentationURL() { final ApplicationConfiguration config = new ApplicationConfiguration( diff --git a/war/src/test/resources/documentation-urls/plugin-documentation-urls-with-nulls.json b/war/src/test/resources/documentation-urls/plugin-documentation-urls-with-nulls.json new file mode 100644 index 000000000..c147f5e1b --- /dev/null +++ b/war/src/test/resources/documentation-urls/plugin-documentation-urls-with-nulls.json @@ -0,0 +1,10 @@ +{ + "foo": { + "url": "https://wiki.jenkins-ci.org/display/JENKINS/foo+plugin" + }, + "bar": { + "url": "https://github.com/jenkinsci/bar-plugin" + }, + "test": { + } +}