Skip to content

Read the local cache file back as UTF-8 in FileCacheStore - #16571

Open
b84330808 wants to merge 1 commit into
apache:3.3from
b84330808:fix-file-cache-store-utf8
Open

b84330808 wants to merge 1 commit into
apache:3.3from
b84330808:fix-file-cache-store-utf8

Conversation

@b84330808

Copy link
Copy Markdown

What is the purpose of the change?

FileCacheStore.refreshCache() writes the local cache file (.metadata, .mapping) with an OutputStreamWriter set to UTF-8, but loadCache() reads it back with FileReader, which uses the platform charset. On JDK 8–17 with a non-UTF-8 default, e.g. GBK on Chinese Windows, any non-ASCII text in the cached MetadataInfo (such as a service parameter value) comes back garbled after a restart.

loadCache() also splits each line on every =, so a value that contains = (base64 padding, a parameter like a=b) is cut at the first one.

This reads the file as UTF-8 and splits only on the first =.

The new FileCacheStoreTest#testLoadCacheReadsBackWhatRefreshCacheWrote writes two entries with refreshCache() and expects loadCache() to return them unchanged. On 3.3 it fails:

expected: <{newKey2=a=b=c, newKey1={"params":{"desc":"订单服务","token":"YWJjZA=="}}}>
 but was: <{newKey2=a, newKey1={"params":{"desc":"订单服务","token":"YWJjZA}>

and with JDK 17 and -Dargline=-Dfile.encoding=GBK the value is also garbled ("desc":"璁㈠崟鏈嶅姟"). It passes with the change.

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

refreshCache() writes the cache file through an OutputStreamWriter with
UTF-8, but loadCache() read it with FileReader, i.e. the platform charset.
On JDK 8-17 with a non-UTF-8 default (for example GBK on Chinese Windows)
non-ASCII text in cached metadata came back garbled.

loadCache() also split each line on every '=', so a value containing '='
(base64 padding, "a=b" parameters) was cut at the first one. Only the
first '=' separates the key now.
@codecov-commenter

codecov-commenter commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.02%. Comparing base (2d9730c) to head (132ee6b).

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16571      +/-   ##
============================================
+ Coverage     61.00%   61.02%   +0.02%     
- Complexity       15    11768   +11753     
============================================
  Files          1953     1953              
  Lines         89286    89286              
  Branches      13478    13478              
============================================
+ Hits          54471    54491      +20     
+ Misses        29213    29200      -13     
+ Partials       5602     5595       -7     
Flag Coverage Δ
integration-tests-java21 32.07% <50.00%> (-0.02%) ⬇️
integration-tests-java8 32.21% <50.00%> (+<0.01%) ⬆️
samples-tests-java21 32.18% <50.00%> (+<0.01%) ⬆️
samples-tests-java8 29.79% <50.00%> (+<0.01%) ⬆️
unit-tests-java11 59.29% <100.00%> (+0.03%) ⬆️
unit-tests-java17 58.71% <100.00%> (+0.01%) ⬆️
unit-tests-java21 58.70% <100.00%> (-0.04%) ⬇️
unit-tests-java25 58.71% <100.00%> (+0.04%) ⬆️
unit-tests-java8 59.27% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants