Prevent NSEE when there is no AddonService (#2493)

The code was already prepared for a nullable default service and then returns a 404 not found.

Fixes #2491

Signed-off-by: Wouter Born <github@maindrain.net>
pull/2499/head
Wouter Born 2021-09-25 20:21:53 +02:00 committed by GitHub
parent cfabfbcf48
commit 641b92324d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 7 deletions

View File

@ -275,13 +275,9 @@ public class AddonResource implements RESTResource {
eventPublisher.post(event);
}
private AddonService getDefaultService() {
for (AddonService addonService : addonServices) {
if (addonService.getId().equals(DEFAULT_ADDON_SERVICE)) {
return addonService;
}
}
return addonServices.iterator().next();
private @Nullable AddonService getDefaultService() {
return addonServices.stream().filter(addonService -> DEFAULT_ADDON_SERVICE.equals(addonService.getId()))
.findFirst().orElse(addonServices.stream().findFirst().orElse(null));
}
private Stream<Addon> getAllAddons(Locale locale) {