add check on null objects
This commit is contained in:
@ -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