From c572fe885ed87a4079fbce0b90abab2a5f9f2867 Mon Sep 17 00:00:00 2001 From: Sabiq Ihab Date: Sat, 29 Jul 2017 12:16:19 +0100 Subject: [PATCH] add check on null objects --- .../com/iluwatar/cqrs/commandes/CommandServiceImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java b/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java index 3ee0d9d3e..f1c88a925 100644 --- a/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java +++ b/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java @@ -23,6 +23,9 @@ public class CommandServiceImpl implements ICommandService { query.setParameter("username", username); author = (Author) query.uniqueResult(); } + if (author == null) { + throw new NullPointerException("Author " + username + " doesn't exist!"); + } return author; } @@ -33,6 +36,9 @@ public class CommandServiceImpl implements ICommandService { query.setParameter("title", title); book = (Book) query.uniqueResult(); } + if (book == null) { + throw new NullPointerException("Book " + title + " doesn't exist!"); + } return book; }