Skip to content

fix: guard waitDirty against spurious wakeups#1765

Merged
gnodet merged 1 commit into
masterfrom
chore/screen-terminal-sonarcloud
Apr 7, 2026
Merged

fix: guard waitDirty against spurious wakeups#1765
gnodet merged 1 commit into
masterfrom
chore/screen-terminal-sonarcloud

Conversation

@gnodet
Copy link
Copy Markdown
Member

@gnodet gnodet commented Apr 7, 2026

Summary

  • Fix SonarCloud java:S2274: Object.wait(timeout) in ScreenTerminal.waitDirty(long) was not in a while loop, making it vulnerable to spurious wakeups.
  • Uses a deadline-based while loop to correctly re-check the dirty flag and compute remaining timeout after each wakeup.

This was flagged as a new issue on PR #1758.

Summary by CodeRabbit

Bug Fixes

  • Improved timeout handling for screen terminal operations with refined deadline-based calculation, ensuring more reliable and precise timing behavior during screen updates and reducing potential timing-related issues.

@gnodet gnodet added this to the 4.0.11 milestone Apr 7, 2026
@gnodet gnodet added bug java Pull requests that update Java code labels Apr 7, 2026
@gnodet gnodet force-pushed the chore/screen-terminal-sonarcloud branch 2 times, most recently from 04af364 to fdb4adf Compare April 7, 2026 03:14
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 7, 2026

Warning

Rate limit exceeded

@gnodet has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 21 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 21 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ce3ba3d0-bdec-412d-b744-b1504ca89f55

📥 Commits

Reviewing files that changed from the base of the PR and between fdb4adf and aa29592.

📒 Files selected for processing (1)
  • builtins/src/main/java/org/jline/builtins/ScreenTerminal.java
📝 Walkthrough

Walkthrough

The waitDirty(long timeout) method in ScreenTerminal.java was refactored from a single wait(timeout) call to a loop-based implementation using System.nanoTime() to compute an absolute deadline, ensuring the wait condition is rechecked after each wakeup.

Changes

Cohort / File(s) Summary
Timeout Polling Loop
builtins/src/main/java/org/jline/builtins/ScreenTerminal.java
Refactored waitDirty(long timeout) to use loop-based polling with absolute deadline calculation via System.nanoTime(), replacing single wait(timeout) call with repeated wait(millis, nanos) invocations that recalculate remaining time until deadline or dirty flag is set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A timeout loop hops 'round and 'round,
With nanoTime precision, so profound,
Each wakeup checks the dirty flag anew,
Deadline-aware, through and through!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: protecting the waitDirty method against spurious wakeups through proper loop-based waiting.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/screen-terminal-sonarcloud

Comment @coderabbitai help to get the list of available commands and usage tips.

Object.wait(timeout) can return due to spurious wakeups, so it must
be called inside a while loop that re-checks the condition. Use a
deadline-based loop to correctly handle the remaining timeout.
@gnodet gnodet force-pushed the chore/screen-terminal-sonarcloud branch from fdb4adf to aa29592 Compare April 7, 2026 03:20
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 7, 2026

@gnodet gnodet merged commit 28dd626 into master Apr 7, 2026
11 checks passed
gnodet added a commit that referenced this pull request Apr 27, 2026
Object.wait(timeout) can return due to spurious wakeups, so it must
be called inside a while loop that re-checks the condition. Use a
deadline-based loop to correctly handle the remaining timeout.
gnodet added a commit that referenced this pull request Apr 27, 2026
Object.wait(timeout) can return due to spurious wakeups, so it must
be called inside a while loop that re-checks the condition. Use a
deadline-based loop to correctly handle the remaining timeout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant