fix: Fix CacheKeyBuilder to correctly handle empty Cacheable keys#18415
fix: Fix CacheKeyBuilder to correctly handle empty Cacheable keys#18415hongkunxu wants to merge 1 commit intoapache:masterfrom
Conversation
|
This pull request has been marked as stale due to 60 days of inactivity. |
|
Hi @FrankChen021 , Could you please tell me why not merge this PR? |
|
close and repen to trigger the CI @hongkunxu |
|
This pull request has been marked as stale due to 60 days of inactivity. |
|
This pull request/issue has been closed due to lack of activity. If you think that |
|
Hi @FrankChen021 , Could you help move this forward? |
|
@hongkunxu Thanks for the contribution. Please address the problems that were highlighted in the CI. Notably,
|
…cheable keys Signed-off-by: Hongkun Xu <xuhongkun666@163.com>
GWphua
left a comment
There was a problem hiding this comment.
Hello @hongkunxu
I am rather confused by the dead-code bug you have mentioned. Can you clarify more on how you have met the bug, or is this PR trying to refactor the code to make the null check more explicit?
The new test cases you have introduced are already passing on the old code. I'm not sure if i'm missing something.
| byte[] cacheableToByteArray = cacheableToByteArray(input); | ||
| if (cacheableToByteArray == null) { | ||
| final byte[] bytes = cacheableToByteArray(input); | ||
| if (bytes == null) { | ||
| invalidKey = true; | ||
| return this; | ||
| } | ||
| appendItem(CACHEABLE_KEY, cacheableToByteArray); | ||
| appendItem(CACHEABLE_KEY, bytes); |
There was a problem hiding this comment.
This change is a pure rename right? Can we leave this untouched?
There was a problem hiding this comment.
Since this PR has been open for quite some time and I no longer recall the original context clearly, I revisited it and found the changes are unnecessary. I’ve closed the PR. Thanks @GWphua for the review.
Bug
CacheKeyBuilder.appendCacheable had a dead-code bug in its null check. The helper method cacheableToByteArray() returns EMPTY_BYTES (not null) when the input Cacheable is null, so the original guard if (cacheableToByteArray == null) could never match that case. Meanwhile, Cacheable.getCacheKey() is declared @nullable and multiple production classes (e.g., RestrictedDataSource, UnnestDataSource, ExternalDataSource) return null from it to signal "uncacheable." That path happened to work only by coincidence — cacheableToByteArray() returned null implicitly when getCacheKey() returned null, and the == null check caught it.
Fix
Refactored cacheableToByteArray to make null handling explicit:
Also simplified the empty-key check from Arrays.equals(key, EMPTY_BYTES) to key.length > 0.
Tests
Added two new test cases in CacheKeyBuilderTest:
Could some committer help to review this PR?
cc @agile @trotter @mcroydon @StFS