From: Roland Haeder Date: Fri, 23 Oct 2015 18:47:02 +0000 (+0200) Subject: Added work-around for NPE "this.user is null". Not a fix! X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=294bf1736ccd210b30a43430049ac5a7a3354d9d;p=jfinancials-war.git Added work-around for NPE "this.user is null". Not a fix! --- 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} - +