From de7df11156998b33508d31ceaff989464ca7c2c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 11 Aug 2016 14:09:36 +0200 Subject: [PATCH] added more checks on user's contact instance (please cherry-pick) --- .../beans/user/JobsUserWebSessionBean.java | 48 ++++--------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index 331f5c53..0e40c412 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -912,42 +912,6 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs this.setUserProfileMode(user.getUserProfileMode()); } - /** - * Uniquely adds given user instance to user list. First an existing - * instance will be removed, then the given instance is being added. - *

- * @param user User instance to add - */ - private void uniqueAddUser (final User user) { - // Make sure the instance is valid - if (null == user) { - // Throw NPE - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserContact() == null) { - // Throw again ... - throw new NullPointerException("user.userContact is null"); //NOI18N - } - - // Get iterator from list - Iterator iterator = this.userList.iterator(); - - // "Walk" through all entries - while (iterator.hasNext()) { - // Get next element - User next = iterator.next(); - - // Is id number the same? - if (Objects.equals(user.getUserId(), next.getUserId())) { - // Found entry, so remove it and abort - this.userList.remove(next); - break; - } - } - - // Add contact to list - this.userList.add(user); - } - /** * Updates list with given user instance *

@@ -958,15 +922,21 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs if (null == user) { // Throw NPE throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserContact() == null) { - // Throw again ... - throw new NullPointerException("user.userContact is null"); //NOI18N } else if (user.getUserId() == null) { // ... again NPE throw new NullPointerException("user.userId is null"); //NOI18N } else if (user.getUserId() < 1) { // Invalid id throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N + } else if (user.getUserContact() == null) { + // Throw again ... + throw new NullPointerException("user.userContact is null"); //NOI18N + } else if (user.getUserContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("user.userContact.contactId is null"); //NOI18N + } else if (user.getUserContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N } // Get iterator from list -- 2.39.5