From b0e582a679266e583c3e4711941455c47f356bb6 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 19 Oct 2015 10:37:05 +0200 Subject: [PATCH] =?utf8?q?Validated=20more=20parameter=20Signed-off-by:Rol?= =?utf8?q?and=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../addressbook/AddressbookSessionBean.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java index d52c1bb..4f9dc70 100644 --- a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java +++ b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java @@ -46,6 +46,30 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb @Override @SuppressWarnings ("unchecked") public List allEntries (final Addressbook addressbook) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("allEntries: addressbook={0} - CALLED!", addressbook)); //NOI18N + + // Validate parameter + if (null == addressbook) { + // Throw NPE + throw new NullPointerException("addressbook is null"); + } else if (addressbook.getAddressbookId() == null) { + // Throw NPE again + throw new NullPointerException("addressbook.addressbookId is null"); + } else if (addressbook.getAddressbookId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); + } else if (addressbook.getAddressbookUser() == null) { + // Throw again NPE + throw new NullPointerException("addressbook.addressbookUser is null"); + } else if (addressbook.getAddressbookUser().getUserId() == null) { + // Throw again NPE + throw new NullPointerException("addressbook.addressbookUser.userId is null"); + } else if (addressbook.getAddressbookUser().getUserId() < 1) { + // Throw again NPE + throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid", addressbook.getAddressbookUser().getUserId())); + } + // Generate query Query query = this.getEntityManager().createNamedQuery("AllAddressbookEntries", List.class); //NOI18N @@ -122,7 +146,7 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb } // Debug message - this.getLoggerBeanLocal().logDebug("allUsersNotSharing: sharingUsers.size()=" + sharingUsers.size()); + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: sharingUsers.size()={0}", sharingUsers.size())); //NOI18N // Init final user list List userList = new LinkedList<>(); @@ -330,7 +354,13 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb throw new NullPointerException("addressbook is null"); //NOI18N } else if (addressbook.getAddressbookUser() == null) { // User instance is null - throw new NullPointerException("addressbook.user should not be null."); //NOI18N + throw new NullPointerException("addressbook.addressbookUser is null."); //NOI18N + } else if (addressbook.getAddressbookUser().getUserId() == null) { + // User instance is null + throw new NullPointerException("addressbook.addressbookUser.userId is null."); //NOI18N + } else if (addressbook.getAddressbookUser().getUserId() < 1) { + // User instance is null + throw new NullPointerException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid.", addressbook.getAddressbookUser().getUserId())); //NOI18N } else if (addressbook.getAddressbookName() == null) { // Address book name not set throw new NullPointerException("addressbook.addressbookName should not be null"); //NOI18N -- 2.39.5