From 8fdc52ba56dc8ef5407dd5c995b217fbe148c5ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 5 Nov 2022 09:24:14 +0100 Subject: [PATCH] Continued: - invoke other (lesser/no parameter) constructor to avoid side effects - checked on parameters of a constructor --- .../model/user/activity/UserActivityLog.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java b/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java index 4052caf..09627d6 100644 --- a/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java +++ b/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java @@ -149,7 +149,7 @@ public class UserActivityLog implements LogableUserActivity { * @param activityMessage Message * @param activityType Type * @param activityUser User instance - * @param activityTimestamp imestamp + * @param activityTimestamp Timestamp */ public UserActivityLog (final String activityMessage, final String activityType, final User activityUser, final Date activityTimestamp) { // Call other constructor @@ -173,9 +173,12 @@ public class UserActivityLog implements LogableUserActivity { *

* @param activityType Type * @param activityUser User instance - * @param activityTimestamp imestamp + * @param activityTimestamp Timestamp */ public UserActivityLog (final String activityType, final User activityUser, final Date activityTimestamp) { + // Invoke oher constructor + this(); + // Make sure all is set if (null == activityType) { // Throw NPE @@ -231,6 +234,15 @@ public class UserActivityLog implements LogableUserActivity { // Call other constructor this(activityMessage, activityType, activityUser, activityTimestamp); + // Validater parameter + if (null == principalName) { + // Throw NPE + throw new NullPointerException("principalName is null"); //NOI18N + } else if (principalName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("principalName is empty"); //NOI18N + } + // Set principal name this.activityPrincipalName = principalName; } @@ -247,6 +259,15 @@ public class UserActivityLog implements LogableUserActivity { // Call other constructor this(activityType, activityUser, activityTimestamp); + // Validater parameter + if (null == principalName) { + // Throw NPE + throw new NullPointerException("principalName is null"); //NOI18N + } else if (principalName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("principalName is empty"); //NOI18N + } + // Set principal name this.activityPrincipalName = principalName; } -- 2.39.5