fix(curse): fix mod conflicts during modpack update #6190
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates CurseInstallTask.java to read previous file names from manifest.json instead of the modpack configuration, which fixes an issue where outdated mods were not being removed during updates. The review feedback points out a potential NullPointerException if the parsed manifest or its files list is null, and suggests adding defensive null checks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| CurseManifest oldManifest = JsonUtils.fromJsonFile(oldManifestFile, CurseManifest.class); | ||
| for (CurseManifestFile oldCurseManifestFile : oldManifest.files()) { | ||
| if (StringUtils.isBlank(oldCurseManifestFile.fileName())) continue; | ||
| Path oldFile = run.resolve("mods/" + oldCurseManifestFile.fileName()); | ||
| if (Files.notExists(oldFile)) continue; | ||
| if (manifest.files().stream().noneMatch(oldCurseManifestFile::equals)) | ||
| Files.deleteIfExists(oldFile); | ||
| } |
There was a problem hiding this comment.
The JsonUtils.fromJsonFile method can return null if the file is empty or invalid. Additionally, oldManifest.files() can also be null if the files field is missing in the JSON. To prevent a potential NullPointerException, we should add defensive null checks for both oldManifest and oldManifest.files() before iterating over the files.
CurseManifest oldManifest = JsonUtils.fromJsonFile(oldManifestFile, CurseManifest.class);
if (oldManifest != null && oldManifest.files() != null) {
for (CurseManifestFile oldCurseManifestFile : oldManifest.files()) {
if (StringUtils.isBlank(oldCurseManifestFile.fileName())) continue;
Path oldFile = run.resolve("mods/" + oldCurseManifestFile.fileName());
if (Files.notExists(oldFile)) continue;
if (manifest.files().stream().noneMatch(oldCurseManifestFile::equals))
Files.deleteIfExists(oldFile);
}
}|
已在atm9整合包升级中测试过确定问题已修复 |
Fix
Fixed an issue where old version mods were not deleted during CurseForge modpack updates, resulting in both old and new mods coexisting and causing
ResolutionException(e.g., CrashAssistant conflicts).Root Cause
In
CurseInstallTask.execute(), the data source for reading the old file list was incorrect:config.getManifest()(modpack.cfg/modpack.json).projectIDandfileID, while thefileNamefield is blank.isBlank()check at L144 always evaluated to true, directlycontinueing and skipping the cleanup of old files.Solution
Changed the source of the old file list from
configto themanifest.jsonlocated in the version root directory (which is written byCurseCompletionTaskand contains the completefileNameinfo).This allows the installation task to correctly obtain the old file names and delete them before installing new mods, preventing duplicate installations.
#4315
#6185