I absolutely dislike the fact that your List could contain null, what is the point of that anyway? Why don't you refactor and return an empty one instead. Assuming that you cannot change that (please double check if you can), don't do it in a single line, just because it's fancy - it will be very unreadable in this particular case. Besides, I am strongly against these helper methods like CollectionsUtils or StringUtils, etc - that only make reading the code worse; not saying for all of them though (guava has some that I really like and use)
Instead, refactor this one to a simpler, more pleasant to look at method:
List<Book> books = library.getBooks();
if(books != null && !books.isEmpty()) {
books.add(book);
} else {
library.setBooks(Collections.singletonList(book));
}
How many seconds did it take you to understand this logic? As, for example opposed, to the other answer here (nothing personal, you made an excellent point).
But this still raises some questions for me personally. Why not move this entire logic to the Library class? What if you want later to add another book to a library? Because you have used Collections.singletonList which is immutable, you will not be able to.
CollectionUtilsisn't for java 8library.getBooks()does not return anOptional