Repository navigation
Conversation
CacheServiceRedisImpl#getImgCache(String) calls RMapCache#get with a null key, which makes Redisson 4.x throw NullPointerException ("map key can't be null").
compressFileKey comes from the optional kkCompressfileKey URL parameter that only archive batch preview carries, so it is null for a plain image URL. With cache.type=redis this makes every image preview fail with HTTP 500.
CacheServiceJDKImpl#getImgCache already guards this case and returns an empty list; align the redis implementation with the same semantics.
klboke
approved these changes
Sep 24, 2026
klboke
left a comment
Contributor
There was a problem hiding this comment.
已核对当前提交 2069d121 的调用链和改动,修复方向正确。普通图片预览不会设置 compressFileKey,Redis 实现此前将 null 直接传给 Redisson RMapCache#get,会抛出异常;提前返回空列表与 JDK 缓存实现及 PictureFilePreviewImpl 的现有处理一致,非空 key 的读取路径不变。
我在该提交上运行了 mvn -q -pl server -DskipTests compile,结果通过。可以合并。建议后续补一条覆盖 null 和空字符串 key 的回归测试,避免同类问题再次出现;这条建议不阻碍本次修复。
Contributor
|
代码有冲突了,么法直接合并了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #793
问题
cache.type=redis时,图片预览必然返回 HTTP 500:PictureFilePreviewImpl在非压缩包场景下把fileAttribute.getCompressFileKey()(此时为null)直接传给了
FileHandlerService#getImgCache,而 redis 实现在取缓存前没有判空,Redisson 4.x 对 null key 会抛 NPE。
改动
只动 1 个文件、7 行:
server/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java为什么这样改
CacheServiceJDKImpl#getImgCache(String)已经有完全相同的判空并返回空集合,PictureFilePreviewImpl也用CollectionUtils.isEmpty(...)兜底,所以返回空集合是既有语义;本次只是把 redis 实现补齐到与 jdk 实现一致。
没有新增依赖(
commons-lang3已在依赖树中),没有改接口,没有改其他实现。验证
new CacheServiceRedisImpl(redissonClient).getImgCache(null))[];getImgCache("")返回[];正常 key 与putImgCache读写回环行为不变HTTP 500,进程日志 NPE 累计 10+ 次HTTP 200并正常返回图片预览页,新进程 NPE 0 次200kkFileView 服务启动完成,耗时:6.06s/Tomcat started on port 8012未改动的同类风险点(说明理由)
CacheServiceRedisImpl的getPDFCache(String)、putImgCache(String, List)同样没有判空,但核对现有全部调用点后确认实参不会是 null:
getPDFCache(String)←FileHandlerService#getConvertedFile(key)← 实参是fileAttribute.getName()putImgCache← 实参是字符串拼接结果(fileName + packagePath/cacheName)因此本次只做最小改动修复已确认的崩溃路径;如需要,可以另外统一加固。