Skip to content

Fix #5525: 修复 Task 进度异常的问题#5543

Merged
Glavo merged 3 commits intoHMCL-dev:mainfrom
Glavo:fix5525
Feb 15, 2026
Merged

Fix #5525: 修复 Task 进度异常的问题#5543
Glavo merged 3 commits intoHMCL-dev:mainfrom
Glavo:fix5525

Conversation

@Glavo
Copy link
Member

@Glavo Glavo commented Feb 15, 2026

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical logic bug in the Task.updateProgress(long count, long total) method where the comparison condition was inverted, causing progress to be incorrectly calculated. The bug would have resulted in progress being set to 100% when tasks were just starting (when total >= count), and attempting to calculate progress as count/total when count exceeded total.

Changes:

  • Fixed inverted condition in updateProgress method: changed if (total >= count) to if (count >= total) to correctly set progress to 1.0 when the task is complete
Comments suppressed due to low confidence (1)

HMCLCore/src/main/java/org/jackhuang/hmcl/task/Task.java:355

  • The updateProgress method lacks test coverage. Consider adding unit tests to verify the progress calculation logic, especially for edge cases:
  • When count equals total (should return 1.0)
  • When count is less than total (should return count/total)
  • When count exceeds total (should return 1.0, not > 1.0)

This would have caught the original bug where the condition was inverted.

    protected void updateProgress(long count, long total) {
        if (count < 0 || total < 0)
            throw new IllegalArgumentException("Invalid count or total: count=" + count + ", total=" + total);

        double progress;
        if (count >= total)
            progress = 1.0;
        else
            progress = (double) count / total;
        updateProgress(progress);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Glavo Glavo merged commit 32a741e into HMCL-dev:main Feb 15, 2026
2 checks passed
@Glavo Glavo deleted the fix5525 branch February 15, 2026 04:30
Jeinse added a commit to Jeinse/HMCL that referenced this pull request Feb 15, 2026
Fix HMCL-dev#5525: 修复 Task 进度异常的问题 (HMCL-dev#5543)
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.

1 participant