Skip to content

fix: handle InterruptedException properly in ProgressBar.close() #193

Open
rubaiyat-bsse wants to merge 1 commit into
ctongfei:mainfrom
rubaiyat-bsse:refactoring-contribution
Open

fix: handle InterruptedException properly in ProgressBar.close() #193
rubaiyat-bsse wants to merge 1 commit into
ctongfei:mainfrom
rubaiyat-bsse:refactoring-contribution

Conversation

@rubaiyat-bsse

Copy link
Copy Markdown

Summary

The close() method in ProgressBar was silently swallowing InterruptedException and ExecutionException with an empty catch block (/* NOOP */). This was flagged by PMD as an EmptyCatchBlock violation (Error Prone category, priority 3)

Problem

Catching InterruptedException without restoring the interrupt flag discards the thread's interrupted state silently. Any code up the call stack that checks Thread.isInterrupted() will never know the interruption happened, which can cause subtle and hard-to-debug issues in multi-threaded environments.

Changes

  • Split the combined catch into two separate handlers
  • InterruptedException → calls Thread.currentThread().interrupt() to restore the interrupt flag per Java best practice
  • ExecutionException → retained as a no-op but with an explanatory comment, since a failed final render is non-critical during shutdown

Testing

All existing tests pass. Behaviour is functionally unchanged.

    The close() method silently swallowed both InterruptedException and
    ExecutionException with an empty catch block (/* NOOP */), which was
    flagged by PMD as an EmptyCatchBlock violation (Error Prone, priority 3).

    Split the combined catch block into two separate handlers:

    - InterruptedException: calls Thread.currentThread().interrupt() to
      restore the interrupt flag, following Java best practice. Swallowing
      this exception without restoring the flag discards thread interruption
      state, making it invisible to the calling thread.

    - ExecutionException: acknowledged with an explanatory comment. A failure
      in the final render is genuinely non-critical since the progress bar is
      already in the process of closing.

    Functionality is unchanged — all existing tests pass.
@rubaiyat-bsse
rubaiyat-bsse force-pushed the refactoring-contribution branch from 2c77256 to 8ac731a Compare July 2, 2026 20:22
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