Skip to content

Fix two xrandr follow-ups from the getConnectionPort work - #3679

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:xrandr-cleanups
Aug 21, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:xrandr-cleanups

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Two follow-ups deliberately deferred from #3660, both in oshi-common and both affecting the Linux/Unix display path only. No CHANGELOG.md entry: both defects live in code #3660 introduced, which is unreleased.

1. Share one xrandr query among a batch of displays

UnixDisplay.getOutputName() called Xrandr.findOutputName(), which ran xrandr --verbose itself, unmemoized. Naming the outputs of an n-display system therefore forked n processes and reparsed the whole output n times — and did it again on every subsequent call.

findOutputName() now takes the parsed data instead of fetching it, which also makes it a pure function, and UnixDisplay holds the supplier it reads from. getDisplays(List<Triplet<…>>) builds a batch around one memoized query, so a batch costs at most one invocation however many displays it holds and however often they are asked; the xrandr fallback getDisplays() hands its displays the map it already realized, so they query nothing further.

The memoization is indefinite rather than expiring, because a Display is an immutable snapshot — the output name matching its connector cannot change over the object's lifetime — and AbstractHardwareAbstractionLayer already re-queries the display list at slowExpiration(), rebuilding the batch with a fresh supplier. A topology change is still picked up at the same cadence as before.

This also drops a null check on the edid parameter that is dead under the package's @NullMarked contract, and adds unit tests for the connector-ID/EDID matching logic, which previously could not be reached from a test without a live X server.

2. Accept the legacy EDID property names an older X server publishes

#3660 tightened EDID block detection from a startsWith("EDID") prefix test to an exact match on EDID:, so that a property merely containing EDID — EDID_HASH: on some drivers — could no longer be mistaken for the EDID itself. That was the right fix for the false positive, but it also dropped the two names an older X server publishes the EDID under:

  • RANDR_EDID (RR_PROPERTY_RANDR_EDID) — the conventional property name randrproto used before 1.3 renamed it to EDID.
  • EDID_DATA — the driver-side atom (EDID_ATOM_NAME in hw/xfree86/modes/xf86Crtc.c) that X.Org Server set through 1.6.

Both are still what xrandr --verbose prints on those servers, and OSHI matched them by prefix before #3660, so a display on one now reports no EDID at all. This matches the three names exactly, keeping the false positive out, and pins all four cases with tests.

Verification

Full gate green locally on macOS (spotless, sortpom, checkstyle, install, forbiddenapis, javadoc, -Paggregate-coverage; 1801 tests, 0 failures), plus -Perror-prone with no NullAway findings. Linux CI green on all eight jobs on the fork (run). The batch-sharing test was negative-tested — dropping the memoize makes it fail with 4 queries instead of 1.

I have no X server running against a pre-1.7 X.Org Server, so the two legacy property names are verified against fixture data and the upstream source history rather than a live server.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Linux display detection and output-name matching.
    • Added support for additional EDID property formats used by display systems.
    • Improved handling of display data when resolving outputs.
  • Performance

    • Reduced repeated display-system queries by sharing cached data across display batches.
  • Tests

    • Added coverage for lazy display data retrieval, EDID matching, connector lookup, and unsupported property formats.

`UnixDisplay.getOutputName()` called `Xrandr.findOutputName()`, which ran
`xrandr --verbose` itself, unmemoized. Every call on every display forked a
process and reparsed the whole output, so naming the outputs of an n-display
system cost n invocations, and did so again on each subsequent call.

`findOutputName()` now takes the parsed xrandr data instead of fetching it,
making it a pure function, and `UnixDisplay` holds the supplier it reads from.
`getDisplays(List<Triplet<...>>)` builds a batch around one memoized query, so
the batch costs at most one invocation however many displays it holds and
however often they are asked; the xrandr fallback `getDisplays()` hands its
displays the map it already realized, so they query nothing further.

The memoization is indefinite rather than expiring: a `Display` is an immutable
snapshot, so the output name matching its connector cannot change over the
object's lifetime, and the hardware abstraction layer already re-queries the
display list on its own schedule, rebuilding the batch with a fresh supplier.

Also drops a null check on `findOutputName()`'s `edid` parameter, dead under
the package's `@NullMarked` contract, and adds unit tests for the matching
logic, which was previously unreachable from a test without a live X server.
#3660 tightened the xrandr EDID block detection from a `startsWith("EDID")`
prefix test to an exact match on `EDID:`, so a property whose name merely
contains EDID -- `EDID_HASH:` on some drivers -- could no longer be mistaken
for the EDID itself. That was the right fix for the false positive, but it
also dropped the two names an older X server publishes the EDID under:

- `RANDR_EDID` (`RR_PROPERTY_RANDR_EDID`), the conventional property name
  randrproto used before 1.3 renamed it to `EDID`.
- `EDID_DATA`, the driver-side atom (`EDID_ATOM_NAME` in
  `hw/xfree86/modes/xf86Crtc.c`) X.Org Server set through 1.6.

Both are still what `xrandr --verbose` prints on those servers, and OSHI
matched them before #3660 by prefix, so a display on one now reports no EDID
at all. Match the three names exactly instead, keeping the false positive out.
@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c9c0176-cadf-4a8c-aa96-7bffbb69b006

📥 Commits

Reviewing files that changed from the base of the PR and between 4dd0db9 and 95f5dc5.

📒 Files selected for processing (5)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/UnixDisplay.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Xrandr.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/UnixDisplayTest.java
  • oshi-common/src/test/java/oshi/util/driver/unix/XrandrTest.java

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (11)
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Error Prone
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (4)
oshi-common/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-common/**/*.java: Before writing any parsing helper, check whether ParseUtil already has one.
oshi-common may not reference com.sun.jna.**, java.lang.foreign.**, or any
System.load/loadLibrary. It must stay pure JDK.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/UnixDisplayTest.java
  • oshi-common/src/test/java/oshi/util/driver/unix/XrandrTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/UnixDisplay.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Xrandr.java
**/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/src/main/java/**/*.java: Every public and protected type and method needs javadoc.
Do not use fully-qualified class names in
code or in javadoc — including inside {@link ...}. Import the type and link the simple name.
New files get a current-year-only
header (Copyright 2026 The OSHI Project Contributors / SPDX-License-Identifier: MIT), even when
copied from an older file; spotless maintains end years on existing files.
Normalize with ParseUtil.getStringValueOrUnknown / getStringValueOrEmpty rather than an
inline ternary.
Do not reach for @Nullable to make a null return legal: the convention is a sentinel, not a
null
— Constants.UNKNOWN or "" for strings, an empty collection or array, and 0/-1/NaN
for numbers, whichever is outside the value's real range.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/UnixDisplay.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Xrandr.java
**/*Test.java

📄 CodeRabbit inference engine (AGENTS.md)

Test files are named *Test.java.

Files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/UnixDisplayTest.java
  • oshi-common/src/test/java/oshi/util/driver/unix/XrandrTest.java
**/src/test/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/src/test/java/**/*.java: Tests must pass there and on real hardware.
Assert on invariants (non-null, correct type, ordering, a plausible range), not on specific values.
Zero and empty collections are legitimate results almost everywhere.
Any oshi-core test that allocates JNA needs
@DisabledIfSystemProperty(named = "os.name", matches = "(?i).*netbsd.*"); the NetBSD CI runner
has no libjnidispatch.

Files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/UnixDisplayTest.java
  • oshi-common/src/test/java/oshi/util/driver/unix/XrandrTest.java
🧠 Learnings (2)
📚 Learning: 2026-08-15T04:17:20.334Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3620
File: oshi-common/src/test/java/oshi/util/driver/linux/DmidecodeTest.java:65-66
Timestamp: 2026-08-15T04:17:20.334Z
Learning: In OSHI Java parser tests that use fixed command-output fixtures, use exact expected-value assertions to verify the parser contract. Reserve invariant-based assertions for tests involving host-dependent live readings, where specific values are not deterministic.

Applied to files:

  • oshi-common/src/test/java/oshi/util/driver/unix/XrandrTest.java
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/UnixDisplay.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/util/driver/unix/Xrandr.java (1)

28-52: LGTM!

Also applies to: 127-127, 149-160, 173-173

oshi-common/src/test/java/oshi/util/driver/unix/XrandrTest.java (1)

16-20: LGTM!

Also applies to: 226-295

oshi-common/src/main/java/oshi/hardware/common/platform/unix/UnixDisplay.java (1)

7-21: LGTM!

Also applies to: 31-31, 50-66, 76-76, 87-123

oshi-common/src/test/java/oshi/hardware/common/platform/unix/UnixDisplayTest.java (1)

10-24: LGTM!

Also applies to: 39-89

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHardwareAbstractionLayer.java (1)

53-53: LGTM!


📝 Walkthrough

Walkthrough

The change adds memoized xrandr data sharing across Unix displays, supports additional EDID property names, updates Linux display construction, and adds coverage for lazy lookup, shared queries, parsing, and output matching.

Changes

Unix display discovery

Layer / File(s) Summary
Xrandr parsing and output lookup
oshi-common/src/main/java/oshi/util/driver/unix/Xrandr.java, oshi-common/src/test/java/oshi/util/driver/unix/XrandrTest.java
Xrandr recognizes EDID:, RANDR_EDID:, and EDID_DATA:. findOutputName uses supplied display data. Tests cover EDID parsing and connector or EDID matching.
Shared lazy xrandr data
oshi-common/src/main/java/oshi/hardware/common/platform/unix/UnixDisplay.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/UnixDisplayTest.java
UnixDisplay stores a memoized xrandr-data supplier. Display batches share one lazy query. Tests verify deferred lookup and query reuse.
Linux display batch wiring
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHardwareAbstractionLayer.java
Linux display creation delegates to the appropriate UnixDisplay.getDisplays overload based on DRM data availability.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 95f5d

This change localizes xrandr query handling and restores support for legacy EDID property names, with no actionable merge-blocking risk remaining after normal checks and review.

Suggested reviewers: ayonization

Poem

A rabbit watched the displays align,
One xrandr query saved each time.
EDIDs bloom in names anew,
DRM paths now guide them through.
“Hop,” said Bun, “the tests all shine!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.93% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the two xrandr follow-up fixes related to the getConnectionPort work.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.19048% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.23%. Comparing base (1fd4d83) to head (95f5dc5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...shi/hardware/common/platform/unix/UnixDisplay.java 76.92% 3 Missing ⚠️
.../platform/linux/LinuxHardwareAbstractionLayer.java 0.00% 0 Missing and 1 partial ⚠️
...on/src/main/java/oshi/util/driver/unix/Xrandr.java 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3679      +/-   ##
============================================
+ Coverage     80.21%   80.23%   +0.02%     
- Complexity     4289     4649     +360     
============================================
  Files           707      707              
  Lines         25532    25541       +9     
  Branches       4302     4303       +1     
============================================
+ Hits          20480    20493      +13     
+ Misses         2838     2828      -10     
- Partials       2214     2220       +6     
Flag Coverage Δ
freebsd 35.62% <76.19%> (+0.10%) ⬆️
linux 39.50% <76.19%> (+0.09%) ⬆️
macos 40.32% <66.66%> (+0.04%) ⬆️
openbsd 34.86% <76.19%> (+0.09%) ⬆️
solaris 36.19% <76.19%> (+0.08%) ⬆️
windows 46.76% <66.66%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit e89495f into oshi:master Aug 21, 2026
18 checks passed
@dbwiddis
dbwiddis deleted the xrandr-cleanups branch August 21, 2026 18:43
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