From c4d435e8017f9e3d25f912c9a35da7c48ac8ed1b Mon Sep 17 00:00:00 2001 From: Halo Dev Bot <87291978+halo-dev-bot@users.noreply.github.com> Date: Thu, 29 Dec 2022 17:48:33 +0800 Subject: [PATCH] [release-2.0] Avoid NPE problems when querying the list of posts in the console (#3075) This is an automated cherry-pick of #3068 /assign ruibaby ```release-note None ``` --- src/main/java/run/halo/app/content/impl/PostServiceImpl.java | 4 ++-- .../java/run/halo/app/content/impl/SinglePageServiceImpl.java | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/run/halo/app/content/impl/PostServiceImpl.java b/src/main/java/run/halo/app/content/impl/PostServiceImpl.java index 60419200c2..f729684e38 100644 --- a/src/main/java/run/halo/app/content/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/content/impl/PostServiceImpl.java @@ -93,7 +93,7 @@ Predicate postListPredicate(PostQuery query) { Predicate paramPredicate = post -> contains(query.getCategories(), post.getSpec().getCategories()) && contains(query.getTags(), post.getSpec().getTags()) - && contains(query.getContributors(), post.getStatus().getContributors()); + && contains(query.getContributors(), post.getStatusOrDefault().getContributors()); String keyword = query.getKeyword(); if (keyword != null) { @@ -159,7 +159,7 @@ private Mono getListedPost(Post post) { }) .flatMap(lp -> setTags(post.getSpec().getTags(), lp)) .flatMap(lp -> setCategories(post.getSpec().getCategories(), lp)) - .flatMap(lp -> setContributors(post.getStatus().getContributors(), lp)) + .flatMap(lp -> setContributors(post.getStatusOrDefault().getContributors(), lp)) .flatMap(lp -> setOwner(post.getSpec().getOwner(), lp)); } diff --git a/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java b/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java index 66b38227e5..e6d2c4811e 100644 --- a/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java +++ b/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java @@ -14,7 +14,6 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.context.ApplicationContext; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.security.core.context.SecurityContext; @@ -61,8 +60,6 @@ public class SinglePageServiceImpl implements SinglePageService { private final CounterService counterService; - private final ApplicationContext applicationContext; - @Override public Mono> list(SinglePageQuery query) { Comparator comparator =