From fe675845e58bf9b50d2475c31fdbf2f835b05f3a Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Tue, 25 Oct 2022 15:01:29 +0200 Subject: [PATCH] fix: fix NPE on user registration without topics --- .../cob/userservice/api/adapters/web/dto/UserDTO.java | 3 ++- .../api/service/consultingtype/TopicService.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java b/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java index b7cbcea95..aade164b9 100644 --- a/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java +++ b/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.common.collect.Lists; import de.caritas.cob.userservice.api.adapters.web.dto.serialization.EncodeUsernameJsonDeserializer; import de.caritas.cob.userservice.api.adapters.web.dto.serialization.UrlDecodePasswordJsonDeserializer; import de.caritas.cob.userservice.api.adapters.web.dto.validation.ValidAge; @@ -117,7 +118,7 @@ public class UserDTO implements UserRegistrationDTO { @ApiModelProperty(required = false, example = "\"[1,5]\"") @JsonProperty("topicIds") - private Collection topicIds; + private Collection topicIds = Lists.newArrayList(); @ApiModelProperty(required = false, example = "\"RELATIVE_COUNSELLING\"") @JsonProperty("counsellingRelation") diff --git a/src/main/java/de/caritas/cob/userservice/api/service/consultingtype/TopicService.java b/src/main/java/de/caritas/cob/userservice/api/service/consultingtype/TopicService.java index 6d2c6cb2c..f6e348517 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/consultingtype/TopicService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/consultingtype/TopicService.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.service.consultingtype; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import de.caritas.cob.userservice.api.config.CacheManagerConfig; import de.caritas.cob.userservice.api.config.apiclient.TopicServiceApiControllerFactory; @@ -67,7 +68,13 @@ private Map getAllTopicsMap(List allTopics) { } public List findTopicsInternalAttributes(Collection topicsList) { - return topicsList.stream().map(this::findTopicInternalIdentifier).collect(Collectors.toList()); + if (topicsList == null) { + return Lists.newArrayList(); + } else { + return topicsList.stream() + .map(this::findTopicInternalIdentifier) + .collect(Collectors.toList()); + } } public String findTopicInternalIdentifier(Integer topicId) {