add check on null objects

This commit is contained in:
Sabiq Ihab
2017-07-29 12:16:19 +01:00
parent a221245909
commit c572fe885e

View File

@ -23,6 +23,9 @@ public class CommandServiceImpl implements ICommandService {
query.setParameter("username", username); query.setParameter("username", username);
author = (Author) query.uniqueResult(); author = (Author) query.uniqueResult();
} }
if (author == null) {
throw new NullPointerException("Author " + username + " doesn't exist!");
}
return author; return author;
} }
@ -33,6 +36,9 @@ public class CommandServiceImpl implements ICommandService {
query.setParameter("title", title); query.setParameter("title", title);
book = (Book) query.uniqueResult(); book = (Book) query.uniqueResult();
} }
if (book == null) {
throw new NullPointerException("Book " + title + " doesn't exist!");
}
return book; return book;
} }