Repository navigation
fix: avoid NPE when previewing images with redis cache - #797
Merged
Merged
Conversation
CacheServiceRedisImpl#getImgCache(String) passed the key straight to Redisson, which throws NullPointerException (map key can't be null) for a null key. Every single-image preview hits this path because compressFileKey is only set for images inside an archive, so with cache.type=redis the preview endpoint always returned HTTP 500. Return an empty list for empty keys, matching CacheServiceJDKImpl. Fixes kekingcn#793
klboke
approved these changes
Oct 8, 2026
klboke
left a comment
Contributor
There was a problem hiding this comment.
Reviewed head c1b9daa and traced PictureFilePreviewImpl -> FileHandlerService -> CacheServiceRedisImpl. Returning an empty list for null/empty archive keys matches the existing JDK cache behavior and avoids calling Redisson for an ordinary image preview; a present key still reads the existing map.
Validation: all 3 CacheServiceRedisImplTests pass locally, including verifyNoInteractions for null/empty keys and a populated archive key. Linux, Windows, and macOS packaging plus PR E2E are all green on this head. No blocking findings.
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.
Problem
With
cache.type=redis, previewing a single image always returns HTTP 500. PDF / Office / archive previews are unaffected.Root cause
PictureFilePreviewImpl#filePreviewHandlepassesfileAttribute.getCompressFileKey()intogetImgCache(String).kkCompressfileKeyis only present when previewing an image inside an archive, so for a plain image the key isnull.CacheServiceRedisImpl#getImgCache(String)forwards that key straight to Redisson, which rejects anullkey withNullPointerException.CacheServiceJDKImpl#getImgCache(String)already guards against an empty key, so only the redis implementation is affected.Fix
Return an empty list for empty keys, aligning the redis implementation with the JDK one (5 lines).
Verification
CacheServiceRedisImplTests(Mockito, no real Redis required):nullkey → empty list, andverifyNoInteractions(redissonClient)Tests run: 3, Errors: 2) and pass after (Tests run: 3, Failures: 0).GET /onlinePreview?url=<base64 image url>withcache.type=redisreturned 500 before, 200 after.Fixes 793