From 3b2eca0242787ae0c08984efb03a79d72f8c9d63 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Fri, 23 Sep 2022 18:47:32 +0200
Subject: [PATCH] Please cherry-pick: - e.g. lockUserAccount() changes
 userAccountStatus to LOCKED which results in   Objects.equals() to return
 false even when it is the same user which causes   an exception being thrown.
 - checking the userId only won't be enough for an other use-case where a new 
  user with same data is being created
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder <roland@mxchange.org>
---
 .../model/user/AddressbookUserSessionBean.java        | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java
index c74cc9c..5469f78 100644
--- a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java
+++ b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java
@@ -152,8 +152,15 @@ public class AddressbookUserSessionBean extends BaseAddressbookEnterpriseBean im
 
 		// Fetch whole list
 		for (final User currentUser : this.fetchAllUsers()) {
-			// Is found?
-			if (Objects.equals(user, currentUser)) {
+			/*
+			 * E.g. userAccountStatus can be fifferent because lockUserAccount
+			 * is setting it BEFORE this method is invoked. So this is enough
+			 * for us in this case. But otherwise e.g. when a new user is
+			 * created with same data, then this method must return FALSE even
+			 * when userId is currently NULL.
+			 */
+			//* NOISY-DEBUG: */ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserExists: currentUser={1},currentUser.userId={2}", this.getClass(), currentUser, currentUser.getUserId())); //NOI18N
+			if ((Objects.equals(user.getUserId(), currentUser.getUserId()) && user.getUserId() != null) || Objects.equals(user, currentUser)) {
 				// Yes, then set flag and exit iteration
 				isFound = true;
 				break;
-- 
2.39.5