Skip to content

Refactor field access#194

Open
rubaiyat-bsse wants to merge 1 commit into
ctongfei:mainfrom
rubaiyat-bsse:refactor-getters
Open

Refactor field access#194
rubaiyat-bsse wants to merge 1 commit into
ctongfei:mainfrom
rubaiyat-bsse:refactor-getters

Conversation

@rubaiyat-bsse

Copy link
Copy Markdown

Summary

Replaced all direct package-private field accesses to ProgressState with their existing public synchronized getter methods in DefaultProgressBarRenderer and ProgressUpdateAction.

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 of ProgressState.

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 across percentage(), ratio(), speed(), and render() with getMax(), getCurrent(), isIndefinite(), getStart(), getExtraMessage()
  • ProgressUpdateAction: replaced 4 direct field accesses across the constructor, refresh(), forceRefresh(), and run() with getStart(), getCurrent(), isPaused(), isAlive()

Testing

All existing tests pass. Functionality is unchanged.

…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.
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