From c51486751f4bb2fb08f0ded2f607e0bd3a1e32fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Mon, 11 Nov 2024 16:23:06 +0100 Subject: [PATCH] RLH-21 - Fix Sonar --- .../wtf/beatrice/releasehive/services/UserServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java b/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java index 0f39dbb..ae0a757 100644 --- a/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java +++ b/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java @@ -38,7 +38,9 @@ public class UserServiceImpl implements UserService if (userRepository.findById(id).isEmpty()) { throw new UsernameNotFoundException(id.toString()); } - userRepository.delete(userRepository.findById(id).get()); + if (userRepository.findById(id).isPresent()) { + userRepository.delete(userRepository.findById(id).get()); + } return true; } }