From: Roland Häder Date: Tue, 31 Mar 2020 23:42:34 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=eac5c1067bcff8dd10afacd65dd37c3e51cf1f6d;p=jcoreee.git Continued: - getStringContextParameter() may throw NPE/IAE if parameterKey is NULL or empty - No need for logging boolean value here - added some comments Signed-off-by: Roland Häder --- 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();