From c20ba3dd51fae1d550fbd01340815828e39b195e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 13 Apr 2016 22:38:39 +0200 Subject: [PATCH] Better check the parameter on missing (but important) stuff --- .../PizzaCategoryWebApplicationBean.java | 16 ++++++++++++++++ .../product/PizzaProductWebApplicationBean.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java index f71ac756..9af316c1 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java @@ -16,6 +16,7 @@ */ package org.mxchange.pizzaapplication.beans.category; +import java.text.MessageFormat; import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; @@ -58,6 +59,21 @@ public class PizzaCategoryWebApplicationBean implements PizzaCategoryWebApplicat @Override public void afterShopCategoryAdded (@Observes final AddedCategoryEvent event) { + // Is all valid? + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedCategory() == null) { + // Throw again ... + throw new NullPointerException("event.addedCategory is null"); //NOI18N + } else if (event.getAddedCategory().getCategoryId() == null) { + // And again ... + throw new NullPointerException("event.addedCategory.categoryId is null"); //NOI18N + } else if (event.getAddedCategory().getCategoryId() < 1) { + // Id is invalid + throw new IllegalArgumentException(MessageFormat.format("event.addedCategory.categoryId={0} is not valid.", event.getAddedCategory().getCategoryId())); //NOI18N + } + // Add it here, too. this.addCategory(event.getAddedCategory()); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java index 4e600f95..f90a5bc9 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java @@ -16,6 +16,7 @@ */ package org.mxchange.pizzaapplication.beans.product; +import java.text.MessageFormat; import java.util.Collections; import java.util.List; import javax.annotation.PostConstruct; @@ -60,6 +61,21 @@ public class PizzaProductWebApplicationBean implements PizzaProductWebApplicatio @Override public void afterShopProductAdded (@Observes final AddedProductEvent event) { + // Is all valid? + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedProduct()== null) { + // Throw again ... + throw new NullPointerException("event.addedProduct is null"); //NOI18N + } else if (event.getAddedProduct().getProductId() == null) { + // And again ... + throw new NullPointerException("event.addedProduct.productId is null"); //NOI18N + } else if (event.getAddedProduct().getProductId() < 1) { + // Id is invalid + throw new IllegalArgumentException(MessageFormat.format("event.addedProduct.productId={0} is not valid.", event.getAddedProduct().getProductId())); //NOI18N + } + // Add it here, too. this.addProduct(event.getAddedProduct()); } -- 2.39.5