From 0e0c0feb00de4d528cf6979a745d0d95b3a2cd28 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Wed, 23 Sep 2020 01:19:14 +0300 Subject: [PATCH] Add missing null check Signed-off-by: Pekka Helenius --- .../java/com/fjordtek/bookstore/web/BookController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java index 7d1e37d..2f1ebd2 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java @@ -213,8 +213,10 @@ public class BookController { Book bookI = bookRepository.findByIsbn(book.getIsbn()); // If existing ISBN value is not attached to the current book... - if (bookI.getId() != book.getId()) { - bindingResult.rejectValue("isbn", "error.user", "ISBN code already exists"); + if (bookI != null) { + if (bookI.getId() != book.getId()) { + bindingResult.rejectValue("isbn", "error.user", "ISBN code already exists"); + } } if (bindingResult.hasErrors()) {