Skip to content

Commit c572fe8

Browse files
committed
add check on null objects
1 parent a221245 commit c572fe8

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ private Author getAuthorByUsername(String username) {
2323
query.setParameter("username", username);
2424
author = (Author) query.uniqueResult();
2525
}
26+
if (author == null) {
27+
throw new NullPointerException("Author " + username + " doesn't exist!");
28+
}
2629
return author;
2730
}
2831

@@ -33,6 +36,9 @@ private Book getBookByTitle(String title) {
3336
query.setParameter("title", title);
3437
book = (Book) query.uniqueResult();
3538
}
39+
if (book == null) {
40+
throw new NullPointerException("Book " + title + " doesn't exist!");
41+
}
3642
return book;
3743
}
3844

0 commit comments

Comments
 (0)