Refactor field access#194
Open
rubaiyat-bsse wants to merge 1 commit into
Open
Conversation
…BarRenderer and ProgressUpdateAction
DefaultProgressBarRenderer and ProgressUpdateAction were accessing
ProgressState's package-private fields (max, current, indefinite,
start, extraMessage, paused, alive) directly, bypassing the existing
public synchronized getter methods.
This created tight coupling (Inappropriate Intimacy) where both
classes depended on the exact internal field layout of ProgressState.
Any future refactoring of ProgressState's internals (e.g., renaming
a field or changing a boolean to an enum) would break both classes.
Replaced all direct field accesses with their corresponding getter
methods: getMax(), getCurrent(), isIndefinite(), getStart(),
getExtraMessage(), isPaused(), isAlive().
This also improves thread-safety: the getters are synchronized,
whereas direct field access was not guaranteed to see consistent
values in a multi-threaded context.
All existing tests pass. Functionality is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaced all direct package-private field accesses to
ProgressStatewith their existing public synchronized getter methods inDefaultProgressBarRendererandProgressUpdateAction.Problem
Both classes were bypassing
ProgressState's getter methods and reading its internal fields (max,current,indefinite,start,extraMessage,paused,alive) directly. This is an Inappropriate Intimacy code smell. The classes are coupled to the exact internal field layout ofProgressState.This also has a thread-safety implication: the getter methods are
synchronized, but direct field reads are not, which could lead to inconsistent reads in multi-threaded scenarios (e.g., parallel stream progress tracking).Changes
DefaultProgressBarRenderer: replaced 11 direct field accesses acrosspercentage(),ratio(),speed(), andrender()withgetMax(),getCurrent(),isIndefinite(),getStart(),getExtraMessage()ProgressUpdateAction: replaced 4 direct field accesses across the constructor,refresh(),forceRefresh(), andrun()withgetStart(),getCurrent(),isPaused(),isAlive()Testing
All existing tests pass. Functionality is unchanged.