From 294bf1736ccd210b30a43430049ac5a7a3354d9d Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 23 Oct 2015 20:47:02 +0200 Subject: [PATCH] Added work-around for NPE "this.user is null". Not a fix! --- .../profile/UserProfileWebRequestBean.java | 25 +++++++++++++++++-- .../UserProfileWebRequestController.java | 10 ++++++++ .../login_start_sharing_addressbook.xhtml | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestBean.java index aefe771b..45eae1dd 100644 --- a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestBean.java @@ -102,8 +102,29 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle // Check all conditions (except for admin) // TODO: Add admin role somehow? - return ((profileMode.equals(ProfileMode.PUBLIC)) - || (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS))); + return ((profileMode.equals(ProfileMode.PUBLIC)) || + (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS))); + } + + @Override + public boolean isProfileLinkVisibleByUser (final User user) { + // Is the user instance valid? + if (null == user) { + // Throw NPE here + throw new NullPointerException("user is null"); + } else if (user.getUserId() == null) { + // Throw NPE again + throw new NullPointerException("user.userId is null"); + } else if (user.getUserId() < 1) { + // Throw NPE again + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); + } + + // Set it here + this.setUser(user); + + // Ask other method + return this.isProfileLinkVisible(); } @Override diff --git a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestController.java b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestController.java index 12e04ebd..437c2d4c 100644 --- a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestController.java +++ b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestController.java @@ -33,6 +33,16 @@ public interface UserProfileWebRequestController extends Serializable { */ boolean isProfileLinkVisible (); + /** + * Checks if given user's profile is visible to the currently logged-in + * user. + *

+ * @param user User instance + *

+ * @return Whether the profile link is visible + */ + boolean isProfileLinkVisibleByUser (final User user); + /** * Checks if the user profile link is visible *

diff --git a/web/login/login_start_sharing_addressbook.xhtml b/web/login/login_start_sharing_addressbook.xhtml index 857df3f3..8158d04a 100644 --- a/web/login/login_start_sharing_addressbook.xhtml +++ b/web/login/login_start_sharing_addressbook.xhtml @@ -38,7 +38,7 @@ #{msg.LOGIN_START_SHARING_TITLE} - + -- 2.39.5