From 7a8aaeb63482fd17ab0432c095d47062d31d1f55 Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 5 Mar 2024 18:11:28 +0800 Subject: [PATCH] 1.fix npe --- .../src/main/java/com/luoo/music/service/SearchService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/luoo_music/src/main/java/com/luoo/music/service/SearchService.java b/luoo_music/src/main/java/com/luoo/music/service/SearchService.java index 05823df..c846041 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/SearchService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/SearchService.java @@ -1,8 +1,11 @@ package com.luoo.music.service; +import java.util.Collections; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import constants.Constants; import net.oschina.j2cache.CacheChannel; @@ -16,6 +19,9 @@ public class SearchService { public List autoComplete(String query, int limit) { List values = (List) cacheChannel.get(Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE, query) .getValue(); + if (CollectionUtils.isEmpty(values)) { + return Collections.emptyList(); + } return limit < values.size() ? values.subList(0, limit) : values; } }