Skip to content

Commit f5aec79

Browse files
committed
Add defensive check for learning purposes
1 parent 314cfeb commit f5aec79

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/com/codesungrape/hmcts/BookAPI/service/BookService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public Book createBook(BookRequest request) {
3939
// ID and created_at are auto-generated by JPA/DB
4040
.build();
4141

42-
return bookRepository.save(newBook);
42+
Book savedBook = bookRepository.save(newBook);
43+
44+
// Defensive check (even though it "shouldn't" happen)
45+
if (savedBook == null) {
46+
throw new IllegalStateException("Failed to save book - repository returned null");
47+
}
48+
49+
return savedBook;
4350
}
4451
}

0 commit comments

Comments
 (0)