Skip to content

Add numeric setSerialNo overload and guard setPreferredResolution - #3416

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:edid-encoder-followups
Jun 27, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:edid-encoder-followups

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 27, 2026 •

Copy link
Copy Markdown
Member

Two small refinements to the EdidUtil encoders added in #3415, prompted by sketching the macOS Apple Silicon synthesis path for #3404 (building an EDID from DisplayAttributes/ProductAttributes):

  • setSerialNo(byte[], long) — writes the raw 32-bit ID serial number little-endian into bytes 12-15. The existing string overload only accepts values that round-trip through getSerialNo (8 uppercase hex digits whose bytes are non-alphanumeric, or 4 alphanumeric characters), so an arbitrary numeric serial could not be set; this overload covers that case.
  • setPreferredResolution now returns without modifying the descriptor when the string has no 'x' separator, instead of throwing StringIndexOutOfBoundsException. A synthesizer that has no resolution to supply can pass an empty string safely.

Both are additive/bugfix changes to EdidUtil (not part of the @PublicApi surface). Tests added for the numeric serial round-trip and the no-separator no-op.

Summary by CodeRabbit

  • New Features

    • Added support for setting EDID serial numbers using a numeric input format.
  • Bug Fixes

    • Preferred resolution updates are now safely ignored when the provided value is missing the required x separator.
    • Numeric serial updates now validate that the value fits within an unsigned 32-bit range.
  • Tests

    • Added coverage for the new serial-number overload and for preferred-resolution no-op behavior with invalid input.

@coderabbitai

coderabbitai Bot commented Jun 27, 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

Run ID: 113dfc9e-593a-4c58-a6a8-dae4be23e021

📥 Commits

Reviewing files that changed from the base of the PR and between d0213ed and 5481e44.

📒 Files selected for processing (2)
  • oshi-common/src/main/java/oshi/util/EdidUtil.java
  • oshi-common/src/test/java/oshi/util/EdidUtilTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-common/src/main/java/oshi/util/EdidUtil.java
  • oshi-common/src/test/java/oshi/util/EdidUtilTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

EdidUtil now accepts a numeric serial number overload and writes it into EDID bytes 12–15 in little-endian order. setPreferredResolution now exits without changes when the input lacks an 'x'. Tests cover both paths.

Changes

EdidUtil enhancements

Layer / File(s) Summary
Serial write and resolution guard
oshi-common/src/main/java/oshi/util/EdidUtil.java, oshi-common/src/test/java/oshi/util/EdidUtilTest.java
Adds setSerialNo(byte[], long) with unsigned 32-bit validation and little-endian byte writes, updates setPreferredResolution to no-op when 'x' is missing, and adds tests for numeric serial round-trip, bounds checks, and resolution parsing behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 I hop through bytes with a tidy tap,
A serial fits in its little-endian wrap.
No x, no parse? I bounce away clean,
EDID stays happy, crisp, and serene.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. 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 summarizes the main changes: a numeric setSerialNo overload and a guard in setPreferredResolution.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@oshi-common/src/main/java/oshi/util/EdidUtil.java`:
- Around line 387-390: Reject out-of-range serial values in
EdidUtil.setSerialNo(byte[], long) instead of silently truncating them. Add a
bounds check at the start of setSerialNo to ensure the long fits in an unsigned
32-bit range (0..0xFFFF_FFFFL), and throw an appropriate exception for invalid
values before writing bytes into the EDID array. Keep the byte-packing logic
unchanged for valid inputs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 004ece7c-4823-428b-a2a8-b077c12e759b

📥 Commits

Reviewing files that changed from the base of the PR and between da5ce68 and d0213ed.

📒 Files selected for processing (2)
  • oshi-common/src/main/java/oshi/util/EdidUtil.java
  • oshi-common/src/test/java/oshi/util/EdidUtilTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/util/EdidUtil.java
🔇 Additional comments (2)
oshi-common/src/main/java/oshi/util/EdidUtil.java (1)

475-482: LGTM!

oshi-common/src/test/java/oshi/util/EdidUtilTest.java (1)

263-269: LGTM!

Also applies to: 271-280

@codecov

codecov Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.12%. Comparing base (da5ce68) to head (5481e44).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3416      +/-   ##
============================================
- Coverage     75.19%   75.12%   -0.08%     
  Complexity       76       76              
============================================
  Files           580      580              
  Lines         21581    21588       +7     
  Branches       3580     3582       +2     
============================================
- Hits          16228    16217      -11     
- Misses         3328     3340      +12     
- Partials       2025     2031       +6     
Flag Coverage Δ
freebsd 26.92% <100.00%> (+<0.01%) ⬆️
linux 31.53% <100.00%> (+0.02%) ⬆️
macos 31.75% <100.00%> (-0.02%) ⬇️
openbsd 26.41% <100.00%> (+0.03%) ⬆️
solaris 28.46% <100.00%> (+0.02%) ⬆️
windows 39.97% <100.00%> (-0.03%) ⬇️

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.

Two small refinements to the EdidUtil encoders for the synthetic-EDID use
case (e.g. building an EDID from macOS DisplayAttributes):

- Add setSerialNo(byte[], long) writing the raw 32-bit ID serial little-endian
  into bytes 12-15, so a numeric serial that the string form can't represent
  (it only accepts values that round-trip through getSerialNo) can still be set.
  The value is validated to fit an unsigned 32-bit range, matching the other
  numeric setters, rather than silently truncating.
- setPreferredResolution now returns without modifying the descriptor when the
  string has no 'x' separator, instead of throwing StringIndexOutOfBoundsException.
@dbwiddis
dbwiddis force-pushed the edid-encoder-followups branch from d0213ed to 5481e44 Compare June 27, 2026 16:48
@dbwiddis
dbwiddis merged commit 7f41eb2 into oshi:master Jun 27, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the edid-encoder-followups branch June 27, 2026 16:56
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