Repository navigation
Extract a common BSD Firmware base - #3547
Conversation
NetBsdFirmware and OpenBsdFirmware were byte-identical apart from the class name: the same memoized triplet, the same three getters, the same blank-to-unknown substitution and the same dmesg bios0 parse. FreeBSD had the identical skeleton around a different source, dmidecode rather than dmesg. A new BsdFirmware base holds the memoization, the getters and the substitution, with a readFirmware hook naming each platform's source. The dmesg parse moves to the base since NetBSD and OpenBSD print the same banner; the dmidecode parse stays with FreeBSD, which is the only platform using it. NetBSD and OpenBSD drop to 22 lines each. Name and description are unavailable from both sources, so all three keep the AbstractFirmware defaults; there is now a test asserting that, since the base could otherwise start reporting something else for them without any platform noticing. The two per-platform parse tests merge into one alongside the base, keeping both platforms' dmesg fixtures, and gain coverage of the substitution that no platform test previously exercised.
📝 WalkthroughWalkthroughCentralizes BSD dmesg firmware acquisition and parsing in ChangesBSD firmware consolidation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3547 +/- ##
============================================
- Coverage 79.28% 79.20% -0.08%
- Complexity 76 4111 +4035
============================================
Files 704 705 +1
Lines 24320 24286 -34
Branches 4050 4038 -12
============================================
- Hits 19281 19236 -45
- Misses 2842 2858 +16
+ Partials 2197 2192 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java (1)
16-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate
readFirmware()across NetBSD and OpenBSD. Both classes now implement the identicaldmesg+parseDmesgdelegation; the shared root cause is thatBsdFirmware.readFirmware()is abstract with no dmesg-based default, forcing every non-dmidecode subclass to repeat the same one-liner.
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java#L16-L21: drop this override onceBsdFirmwareprovides a defaultreadFirmware()implementation based ondmesg.oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java#L16-L21: drop this override for the same reason; onlyFreeBsdFirmwarewould continue to overridereadFirmware()fordmidecode.♻️ Suggested direction (requires editing BsdFirmware.java, not in this file set)
protected abstract class BsdFirmware extends AbstractFirmware { ... - protected abstract Triplet<String, String, String> readFirmware(); + protected Triplet<String, String, String> readFirmware() { + return parseDmesg(ExecutingCommand.runNative("dmesg")); + }Then remove the override from
NetBsdFirmwareandOpenBsdFirmware, keeping onlyFreeBsdFirmware'sdmidecode-based override.🤖 Prompt for 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. In `@oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java` around lines 16 - 21, Remove the duplicate readFirmware() overrides from NetBsdFirmware.java and OpenBsdFirmware.java at lines 16-21, and add the shared dmesg/parseDmesg default implementation to BsdFirmware.readFirmware(). Keep FreeBsdFirmware’s dmidecode-based override unchanged.oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdFirmwareTest.java (1)
98-105: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover whitespace-only attributes in the normalization test.
This test verifies null and empty values, but not whitespace-only manufacturer/version/date values—the behavior provided by
Util.isBlank. Add a fixture whosereadFirmware()returns values such as" ","\t", and" ".🤖 Prompt for 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. In `@oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdFirmwareTest.java` around lines 98 - 105, Extend testBlankAttributesBecomeUnknown in BsdFirmwareTest with a fixture whose readFirmware() returns whitespace-only manufacturer, version, and release-date values such as spaces and tabs, then assert each accessor still returns Constants.UNKNOWN. Preserve the existing null/empty-value coverage.
🤖 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.
Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java`:
- Around line 16-21: Remove the duplicate readFirmware() overrides from
NetBsdFirmware.java and OpenBsdFirmware.java at lines 16-21, and add the shared
dmesg/parseDmesg default implementation to BsdFirmware.readFirmware(). Keep
FreeBsdFirmware’s dmidecode-based override unchanged.
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdFirmwareTest.java`:
- Around line 98-105: Extend testBlankAttributesBecomeUnknown in BsdFirmwareTest
with a fixture whose readFirmware() returns whitespace-only manufacturer,
version, and release-date values such as spaces and tabs, then assert each
accessor still returns Constants.UNKNOWN. Preserve the existing null/empty-value
coverage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6e22dcd8-8ad3-49da-ab68-6e118316173b
📒 Files selected for processing (8)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdFirmwareTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmwareTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmwareTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmwareTest.java
💤 Files with no reviewable changes (2)
- oshi-common/src/test/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmwareTest.java
- oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmwareTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
- 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: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 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/hardware/common/platform/unix/BsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.java (1)
10-25: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java (2)
1-84: LGTM!Also applies to: 91-95
85-90: 🎯 Functional CorrectnessNo change needed.
String.split("vendor")without a limit uses only one delimiter, so it does preserve vendor names that containvendorin the middle.> Likely an incorrect or invalid review comment.oshi-common/src/test/java/oshi/hardware/common/platform/unix/BsdFirmwareTest.java (1)
1-97: LGTM!Also applies to: 106-123
oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmwareTest.java (1)
41-42: LGTM!
NetBSD and OpenBSD both overrode readFirmware with the same one-liner, so make the dmesg banner the base's default and drop both overrides. FreeBSD keeps its dmidecode override, which is now the one place a BSD declares a different source. Both platform classes are down to a declaration. Also narrows parseDmesg from protected to package-private, since with the default in place no subclass calls it. The default makes FreeBSD's override load-bearing in a way it was not when readFirmware was abstract: deleting it would silently switch FreeBSD to reading dmesg, while the parseDmiDecode tests kept passing because the parse itself is untouched. Added a guard asserting FreeBsdFirmware declares readFirmware itself, verified to fail when the override is removed.
There was a problem hiding this comment.
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/hardware/common/platform/unix/BsdFirmware.java`:
- Line 82: Restore protected visibility on BsdFirmware.parseDmesg so subclasses
outside its package, including external subclasses, can continue accessing it.
Do not leave the method package-private unless the API-breaking change is
explicitly intended and documented.
🪄 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 Plus
Run ID: 3f9f0e2a-2dbd-4992-94a8-5837746af2d9
📒 Files selected for processing (4)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmwareTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (10)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 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/hardware/common/platform/unix/BsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java
🔇 Additional comments (4)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java (1)
15-15: LGTM!Also applies to: 52-63
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdFirmware.java (1)
11-15: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdFirmware.java (1)
11-15: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmwareTest.java (1)
11-11: LGTM!Also applies to: 43-44, 50-56
Audit item 13a. 8 files.
Scope correction first
The roadmap estimated PowerSource + Firmware at ~183 duplicated lines. Re-querying Sonar before scoping, the real figure is 74, and none of it is in PowerSource:
NetBsdFirmwareOpenBsdFirmwareMacFirmwareWindowsFirmwarePowerSource reports zero. The Windows twins are fat (326 / 323 against a 90-line base) but that is SetupAPI enumeration and battery IOCTLs, with JNA
StructureandMemoryagainst FFMMemorySegmentinterleaved at every level — the same Axis-A shape already left alone for COM/PDH and Mac OSProcess. This PR does the Firmware half only.What changed
NetBsdFirmwareandOpenBsdFirmwarewere byte-identical apart from the class name: same memoized triplet, same three getters, same blank-to-unknown substitution, samedmesgbios0parse. FreeBSD had the identical skeleton around a different source.New
oshi.hardware.common.platform.unix.BsdFirmware(joining the existingBsd*family in that package) holds the memoization, getters and substitution behind areadFirmware()hook that names each platform's source. Thedmesgparse moves to the base since NetBSD and OpenBSD print the same banner;parseDmiDecodestays with FreeBSD as its only user.NetBsdFirmwareOpenBsdFirmwareFreeBsdFirmwareTests
The two per-platform parse tests merge into
BsdFirmwareTest, keeping both platforms' real dmesg fixtures rather than dropping one as redundant. It also gains coverage no platform test had: that blank fields becomeConstants.UNKNOWN(the parse returns null/empty and the base is what substitutes), and thatgetName/getDescriptionstill fall through to theAbstractFirmwaredefaults — neither source supplies them, and a base could otherwise start answering for them without any platform noticing.Left alone, deliberately
MacFirmware↔WindowsFirmware, 23 lines. This is the memoized-Quintetaccessor boilerplate. Hoisting it would need a shape only 2 of 8 platforms use — Linux memoizes aPair, the BSDs aTriplet, AIX and Solaris return constants — so pushing it intoAbstractFirmwarewould force-merge four different carrier shapes. Worth revisiting only if the other platforms are ever unified onto one carrier.BATTERY_SYSTEM_BATTERY/BATTERY_IS_SHORT_TERM), theidev < 100loop bounds, themaxCapacitySafefallback chain and the mV→V voltage scaling with its amperage derivation. All agree. That is targeted spot-checking of the highest-risk arithmetic, not an exhaustive line-by-line audit of two 320-line native methods — if you want that, it deserves its own pass.Full gate green on
oshi-common,oshi-core,oshi-core-ffmplus a clean full-reactorinstall, 0 tests failed. BSD runtime is CI-only;unix.yamlis manual-dispatch for NetBSD/OpenBSD, and the changed code is pure parsing already covered by the merged tests.No CHANGELOG — no user-observable behavior change.
Summary by CodeRabbit