From eac5c1067bcff8dd10afacd65dd37c3e51cf1f6d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 1 Apr 2020 01:42:34 +0200 Subject: [PATCH] Continued: - getStringContextParameter() may throw NPE/IAE if parameterKey is NULL or empty - No need for logging boolean value here - added some comments MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jcoreee/bean/faces/BaseFacesBean.java | 19 +++++++++++++------ .../exceptions/CustomExceptionHandler.java | 6 ++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java b/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java index 4fd4670..699c5a2 100644 --- a/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java +++ b/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java @@ -206,9 +206,19 @@ public abstract class BaseFacesBean implements Serializable { *

* @return Property value *

- * @throws NullPointerException If given key is not found + * @throws NullPointerException If given key is NULL or not found + * @throws IllegalArgumentException If given key is empty */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { + protected String getStringContextParameter (final String parameterKey) throws NullPointerException, IllegalArgumentException { + // Is the parameter valid? + if (null == parameterKey) { + // Throw NPE + throw new NullPointerException("parameterKey is null"); //NOI18N + } else if (parameterKey.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("parameterKey is empty"); //NOI18N + } + // Get context parameter final String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); @@ -242,11 +252,8 @@ public abstract class BaseFacesBean implements Serializable { // Try to get context parameter final String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - final boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; + return (Boolean.parseBoolean(contextParameter) == Boolean.TRUE); } /** diff --git a/src/org/mxchange/jcoreee/exceptions/CustomExceptionHandler.java b/src/org/mxchange/jcoreee/exceptions/CustomExceptionHandler.java index 86ae361..bfa35b9 100644 --- a/src/org/mxchange/jcoreee/exceptions/CustomExceptionHandler.java +++ b/src/org/mxchange/jcoreee/exceptions/CustomExceptionHandler.java @@ -36,7 +36,8 @@ import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; * A custom exception handler for nice output. This code is heavily based on * this [1] example. *

- * 1: https://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/ + * 1: + * https://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/ *

* @author Roland Häder */ @@ -89,9 +90,10 @@ public class CustomExceptionHandler extends ExceptionHandlerWrapper { @Override public void handle () throws FacesException { - + // Get iterator. Please see below remove() call why a for(Foo foo:allFoos()) cannot work. final Iterator iterator = this.getUnhandledExceptionQueuedEvents().iterator(); + // Loop through all while (iterator.hasNext()) { final ExceptionQueuedEvent event = iterator.next(); final ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource(); -- 2.39.5