mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-14 02:16:06 +00:00
add check on null objects
This commit is contained in:
1 parent
a221245909
commit
c572fe885e
1 file changed
+6
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user