From 14b210e223d10cead14ca658564739b54d12eb4d Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Tue, 6 Dec 2022 14:52:14 +0800 Subject: [PATCH] fix: compartor exception in post list (#2854) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bugfix /area core #### What this PR does / why we need it: 修复文章列表查询时的类型转换错误 文章列表查询将 collectList 错写为 collectSortedList 导致此 `Contributor cannot be cast to class java.lang.Comparable`, collectSortedList 会使用 `Arrays.sort(a, (Comparator) c)`,这需要目标类实现 Comparable 才行,而此处并不需要自然排序。 #### Which issue(s) this PR fixes: Fixes #2830 #### Special notes for your reviewer: 此 bug 的复现方式为: 编辑一篇文章保存后,在使用另一个用户账户编辑此文章并发布就会出现,而使用此 PR 后问题消失,此问题只对 Contributor 这个类型有效它不是自定义模型类,而 Tag 和 Category 都是自定义模型 继承了 AbstractExtension 而它 实现了 Comparable 接口。 /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note 修复文章列表查询时的类型转换错误 ``` --- .../java/run/halo/app/content/impl/PostServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 3c5f0984c..60419200c 100644 --- a/src/main/java/run/halo/app/content/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/content/impl/PostServiceImpl.java @@ -165,7 +165,7 @@ public class PostServiceImpl implements PostService { private Mono setTags(List tagNames, ListedPost post) { return listTags(tagNames) - .collectSortedList() + .collectList() .doOnNext(post::setTags) .map(tags -> post) .switchIfEmpty(Mono.defer(() -> Mono.just(post))); @@ -173,7 +173,7 @@ public class PostServiceImpl implements PostService { private Mono setCategories(List categoryNames, ListedPost post) { return listCategories(categoryNames) - .collectSortedList() + .collectList() .doOnNext(post::setCategories) .map(categories -> post) .switchIfEmpty(Mono.defer(() -> Mono.just(post))); @@ -181,7 +181,7 @@ public class PostServiceImpl implements PostService { private Mono setContributors(List contributorNames, ListedPost post) { return listContributors(contributorNames) - .collectSortedList() + .collectList() .doOnNext(post::setContributors) .map(contributors -> post) .switchIfEmpty(Mono.defer(() -> Mono.just(post)));