[Bugfix] 修复 #6348 资源包管理处理非UTF-8编码的options.txt文件时出错#6351
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34d122b4b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1c167216f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (detected == null || !detected.isSupported()) return OperatingSystem.NATIVE_CHARSET; | ||
| var charset = detected.getCharset(); | ||
| if (charset == StandardCharsets.UTF_8 || charset == StandardCharsets.US_ASCII) return StandardCharsets.UTF_8; | ||
| return OperatingSystem.NATIVE_CHARSET; |
There was a problem hiding this comment.
Preserve the detected non-UTF-8 charset
When options.txt is encoded in a supported non-UTF-8 charset that differs from the current JVM native charset, such as an instance copied from a GBK Windows machine to a UTF-8 Linux/macOS install or a UTF-16 file with a BOM, this branch discards the charset UniversalDetector found and forces loadOptions() to decode with OperatingSystem.NATIVE_CHARSET. That still produces mojibake before the resource pack lists are parsed and later rewritten, so the non-UTF-8 fix only works when the file happens to match the local native charset; return the detected charset for supported non-ASCII encodings instead of falling back here.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
无需担心,这种情况MC也读取不了,就不管了(
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79dc5c923f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…leUtils and ResourcePackManager
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d7c031405
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sb.append(entry.getKey()).append(":").append(entry.getValue()).append(System.lineSeparator()); | ||
| } | ||
| FileUtils.saveSafely(optionsFile, sb.toString()); | ||
| FileUtils.saveSafely(optionsFile, sb.toString(), optionsFileEncoding); |
There was a problem hiding this comment.
Use a Unicode-capable charset for ASCII-only options
When an existing options.txt contains only ASCII (the normal case for a fresh instance), EncodingDetector.MODERN_WEB selects US-ASCII; if the user then enables a resource pack such as 中文.zip, this save silently replaces the newly inserted filename characters with ?. Minecraft consequently receives the wrong resource-pack ID and the activation does not persist, so ASCII detection should fall back to UTF-8 or the selected charset should be upgraded when it cannot encode the resulting content.
Useful? React with 👍 / 👎.
| return options; | ||
| } | ||
|
|
||
| EncodingDetector.Encoding bestEncoding = EncodingDetector.MODERN_WEB.detect(bytes).bestEncoding(); |
There was a problem hiding this comment.
Mark the nullable detector result explicitly
bestEncoding() is explicitly handled as possibly null on the following line, but this local variable omits @Nullable, leaving its nullability implicit contrary to the repository's Java nullability requirement; annotate the local declaration accordingly.
AGENTS.md reference: AGENTS.md:L7-L9
Useful? React with 👍 / 👎.

Fixes #6348