fix: avoid NPE when previewing images with redis cache - #797
Open
baiyu-jujuc wants to merge 1 commit into
Open
baiyu-jujuc wants to merge 1 commit into
baiyu-jujuc wants to merge 1 commit into
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
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