Skip to content

Extract shared BSD parsers and add cross-platform unit tests - #3312

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:refactor/bsd-shared-parsers
May 31, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:refactor/bsd-shared-parsers

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Consolidate near-identical Disklabel and systat sensor parsing from oshi.driver.unix.{openbsd,netbsd} into a new shared oshi.driver.unix.bsd package, so the parsing logic lives in one place and is reachable from any OS for test coverage.
  • Split parse loops out of FstatUtil (openbsd/netbsd) and ProcstatUtil (freebsd/dragonflybsd) so each pure-parse method takes a List<String> and can be exercised against sample command output without needing the live OS.
  • Add cross-platform unit tests covering the extracted parsers. Existing live-system smoke tests remain gated to their target OS.

What changed

New shared driver package: oshi.driver.unix.bsd

  • bsd.disk.Disklabel replaces the per-OS Disklabel copies; partition parsing accepts an injectable (disk,name) -> (major,minor) lookup so tests don't shell out to stat. totalSectors is parsed as long for both platforms (the OpenBSD copy previously used getFirstIntValue, which would overflow for >2 TiB disks at 512-byte sectors — NetBSD's copy already had this fix).
  • bsd.Systat exposes parseSensors, parsePowerSourceNames, parseBatteryFields and an immutable BatteryFields holder. OpenBsdSensors/NetBsdSensors shrink to thin AbstractSensors subclasses that delegate to Systat::querySensors; OpenBsdPowerSource/NetBsdPowerSource use Systat.queryBatteryFields for the systat sensor portion of their battery query.

Parse-method split in existing utils

  • FstatUtil (netbsd, openbsd) — parseCwdFromFstat, parseOpenFiles static methods called by the existing public methods.
  • ProcstatUtil (dragonflybsd, freebsd) — parseCwdFromFstat / parseCwdMap / parseCwd / parseOpenFiles static methods called by the existing public methods.

Tests

  • DisklabelTest, SystatTest: exercise the new shared parsers against sample disklabel / systat output. Live-system smoke tests remain gated to OpenBSD/NetBSD.
  • FstatUtilTest (netbsd, openbsd) and ProcstatUtilTest (dragonflybsd, freebsd): add parse-method coverage that runs on any CI platform; per-OS integration tests are gated as before.
  • module-info.test: add opens for oshi.driver.unix.bsd[.disk] and oshi.util.platform.unix.dragonflybsd; remove the now-empty per-OS disk opens.

Why

The recent DragonFly/NetBSD ports landed by copy-rename from the FreeBSD/OpenBSD code, leaving near-byte-identical parsing classes side by side. The previously added OS-gated tests don't run on the linux/mac/win CI runners, so codecov shows 0% coverage for the new code. Extracting the pure parsing into a shared, OS-agnostic location lets us write tests that run on every platform and cover the parsing logic for both OpenBSD and NetBSD at once.

Net effect

  • 27 files changed, +1105 / -597 lines (net +508, mostly tests).
  • 100 net-new test cases that run on every CI platform.
  • Duplicated parsing logic between OpenBSD and NetBSD eliminated.

Test plan

  • mvn -pl oshi-core verify passes (compile, spotless, checkstyle, forbiddenapis, tests)
  • 211 tests found / 121 successful / 90 skipped (OS gates) / 0 failed locally on macOS
  • CI confirms no regressions on linux / mac / windows / openbsd / netbsd / freebsd / dragonfly
  • codecov delta shows coverage gain on the new oshi.driver.unix.bsd package and the refactored fstat/procstat utils

Summary by CodeRabbit

  • New Features

    • Added BSD sensor detection (CPU temps, fan speeds, voltage) and battery/power-source metrics on OpenBSD/NetBSD.
    • Added disk metadata retrieval with robust fallback handling.
  • Refactor

    • Consolidated BSD platform parsing into shared utilities and extracted reusable parsers.
  • Tests

    • Added and expanded unit/integration tests for BSD sensors, disk parsing, and proc/fstat parsing utilities.

OpenBSD and NetBSD shipped near-identical copies of disklabel and systat
sensor parsing; consolidate them under oshi.driver.unix.bsd so the
parsing logic has a single home and is reachable from any OS for test
coverage. Split the FstatUtil/ProcstatUtil parsing loops out of their
ExecutingCommand wrappers so each pure-parse method takes a List<String>
and can be exercised with sample command output.

- New oshi.driver.unix.bsd.disk.Disklabel replaces the per-OS copies in
  oshi.driver.unix.{openbsd,netbsd}.disk; partition parsing accepts an
  injectable major/minor lookup. totalSectors parses as long for both
  platforms (OpenBSD copy previously used getFirstIntValue, which would
  overflow for >2 TiB disks at 512-byte sectors).
- New oshi.driver.unix.bsd.Systat exposes parseSensors,
  parsePowerSourceNames, parseBatteryFields and an immutable
  BatteryFields holder. OpenBsdSensors/NetBsdSensors shrink to thin
  AbstractSensors subclasses that delegate to Systat::querySensors;
  OpenBsdPowerSource/NetBsdPowerSource use Systat.queryBatteryFields for
  the systat sensor portion.
- FstatUtil (netbsd, openbsd) and ProcstatUtil (dragonflybsd, freebsd)
  now have parseCwdFromFstat / parseOpenFiles / parseCwdMap / parseCwd
  static methods called by the existing public methods, so command
  execution and parsing are separable.

Tests:
- DisklabelTest, SystatTest exercise the new parsers with sample
  disklabel and systat output; live-system smoke tests remain gated to
  OpenBSD/NetBSD/DragonFly.
- FstatUtilTest and ProcstatUtilTest in netbsd/openbsd/freebsd/
  dragonflybsd packages add parse-method coverage that runs on any CI
  platform.
- module-info.test adds opens for oshi.driver.unix.bsd[.disk] and
  oshi.util.platform.unix.dragonflybsd; removes the now-empty per-OS
  disk opens.
@coderabbitai

coderabbitai Bot commented May 31, 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: b8d5d349-a979-4163-a721-03c7d44a20a8

📥 Commits

Reviewing files that changed from the base of the PR and between 494aed2 and 9ec34fd.

📒 Files selected for processing (6)
  • oshi-core/src/main/java/oshi/driver/unix/bsd/Systat.java
  • oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.java
  • oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java
  • oshi-core/src/test/java/oshi/util/platform/unix/openbsd/FstatUtilTest.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.java
  • oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java
  • oshi-core/src/main/java/oshi/driver/unix/bsd/Systat.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🔇 Additional comments (2)
oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java (1)

50-51: LGTM!

Also applies to: 60-61

oshi-core/src/test/java/oshi/util/platform/unix/openbsd/FstatUtilTest.java (1)

55-56: LGTM!


📝 Walkthrough

Walkthrough

This PR centralizes BSD sensor and disk parsing into shared drivers (Systat, Disklabel), migrates NetBSD/OpenBSD platform code to use them, extracts parsing helpers from several platform utilities, and adds unit and gated live tests.

Changes

BSD Utility Consolidation and Parsing Extraction

Layer / File(s) Summary
New BSD shared sensor and disk drivers
oshi-core/src/main/java/oshi/driver/unix/bsd/Systat.java, oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java, oshi-core/src/main/java/oshi/driver/unix/bsd/package-info.java, oshi-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java
Adds Systat to parse systat -ab sensors into CPU temperature, fan RPMs, voltage, and per-power-source BatteryFields; adds Disklabel to parse disklabel -n with df fallback for label, DUID, size, and partitions; includes package-level docs.
NetBSD platform integration
oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHWDiskStore.java, oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java, oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdSensors.java
Repoints imports to shared Disklabel and Systat; NetBsdSensors and NetBsdPowerSource now delegate sensor and battery parsing to Systat.
OpenBSD platform integration
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java, oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.java, oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdSensors.java
Repoints imports to shared Disklabel and Systat; OpenBsdPowerSource and OpenBsdSensors now delegate sensor and battery parsing to Systat.
Extract testable parsing methods
oshi-core/src/main/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtil.java, oshi-core/src/main/java/oshi/util/platform/unix/freebsd/ProcstatUtil.java, oshi-core/src/main/java/oshi/util/platform/unix/netbsd/FstatUtil.java, oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java
Extracts parsing logic into reusable public methods (e.g., parseCwdFromFstat, parseOpenFiles, parseCwdMap, parseCwd) and wires existing getters to delegate to them.
Test coverage for new drivers
oshi-core/src/test/java/oshi/driver/unix/bsd/SystatTest.java, oshi-core/src/test/java/oshi/driver/unix/bsd/disk/DisklabelTest.java
Adds unit tests for Systat parsing (temps, fans, volt, Wh/Ah conversions, defaults) and Disklabel parsing (header, partitions, df fallback, large sizes); includes OS-gated live smoke tests.
Test coverage for refactored utilities
oshi-core/src/test/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtilTest.java, oshi-core/src/test/java/oshi/util/platform/unix/freebsd/ProcstatUtilTest.java, oshi-core/src/test/java/oshi/util/platform/unix/netbsd/FstatUtilTest.java, oshi-core/src/test/java/oshi/util/platform/unix/openbsd/FstatUtilTest.java
Adds focused unit tests for parsing helpers and retains gated live tests for runtime behavior.
Test infrastructure updates
oshi-core/src/test/java/module-info.test
Updates JUnit --add-opens for new packages (oshi.driver.unix.bsd, oshi.driver.unix.bsd.disk, oshi.util.platform.unix.dragonflybsd) and removes opens for moved/removed packages.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 I hopped through code with cheer,
Merged drivers far and near.
Sensors parsed and disks aligned,
Tests assure the paths we find,
A tidy burrow, bright and clear!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.87% 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 "Extract shared BSD parsers and add cross-platform unit tests" is a clear, concise summary of the main changes: consolidating BSD parsing code into a shared package and adding unit tests.
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.

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

✨ 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 and usage tips.

@codecov

codecov Bot commented May 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.36842% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.30%. Comparing base (1373684) to head (9ec34fd).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...main/java/oshi/driver/unix/bsd/disk/Disklabel.java 66.66% 15 Missing and 2 partials ⚠️
...rdware/platform/unix/netbsd/NetBsdPowerSource.java 0.00% 12 Missing ⚠️
...ore/src/main/java/oshi/driver/unix/bsd/Systat.java 87.95% 4 Missing and 6 partials ⚠️
...java/oshi/util/platform/unix/netbsd/FstatUtil.java 60.00% 2 Missing ⚠️
...i/hardware/platform/unix/netbsd/NetBsdSensors.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3312      +/-   ##
============================================
+ Coverage     71.77%   72.30%   +0.52%     
  Complexity       76       76              
============================================
  Files           433      434       +1     
  Lines         16846    16879      +33     
  Branches       2748     2746       -2     
============================================
+ Hits          12092    12204     +112     
+ Misses         3268     3177      -91     
- Partials       1486     1498      +12     
Flag Coverage Δ
linux 38.93% <72.36%> (+0.63%) ⬆️
macos 39.23% <72.36%> (+0.61%) ⬆️
windows 46.69% <72.36%> (+0.54%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java (1)

52-62: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

parseOpenFiles returns -1 for empty input, breaking the non-negative open-files contract.

Unlike the NetBSD/DragonFlyBSD counterparts (which guard with size() > 1 / fd > 0 ? fd - 1 : 0), this method subtracts the header unconditionally. If fstat -sp <pid> returns no lines (command failure, dead process), fd stays 0 and the method returns -1. That value flows straight through getOpenFiles(int) into OpenBsdOSProcess.getOpenFiles(), surfacing a negative count to callers.

Guard the subtraction as the sibling parsers do.

🛡️ Proposed fix
-        // subtract 1 for header row
-        return fd - 1;
+        // subtract 1 for header row, but never go negative on empty/failed output
+        return fd > 0 ? fd - 1 : 0;

Note: testParseOpenFilesEmpty in FstatUtilTest currently asserts is(-1L) and would need to be updated to is(0L) after this change.

🤖 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-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java`
around lines 52 - 62, parseOpenFiles currently always subtracts 1 for a header
and can return -1 for empty input; change parseOpenFiles in FstatUtil so it
guards the header subtraction (e.g., only subtract when fd > 0 or when
fstatLines.size() > 1) and return 0 instead of negative values, ensuring callers
like getOpenFiles(int) and OpenBsdOSProcess.getOpenFiles() never see a negative
count; also update the FstatUtilTest.testParseOpenFilesEmpty expectation from
-1L to 0L.
🧹 Nitpick comments (2)
oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java (2)

86-91: ⚡ Quick win

Resolve major/minor only for rows that become partitions.

majorMinorLookup.apply(...) runs before the split.length > 4 guard, so the default lookup (getMajorMinor) spawns a stat -f process for rows that are subsequently discarded (e.g. the c "entire disk" row and short rows like i:). Move the lookup inside the guard to avoid the extra external command per filtered row.

♻️ Proposed change
                 String[] split = ParseUtil.whitespaces.split(line.trim(), 9);
                 String name = split[0].substring(0, 1);
-                Pair<Integer, Integer> majorMinor = majorMinorLookup.apply(diskName, name);
                 if (split.length > 4) {
+                    Pair<Integer, Integer> majorMinor = majorMinorLookup.apply(diskName, name);
                     partitions.add(new HWPartition(diskName + name, name, split[3], duid + "." + name,
                             ParseUtil.parseLongOrDefault(split[1], 0L) * bytesPerSector, majorMinor.getA(),
                             majorMinor.getB(), split.length > 5 ? split[split.length - 1] : ""));
                 }
🤖 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-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java` around
lines 86 - 91, The code calls majorMinorLookup.apply(diskName, name) before
checking split.length > 4, causing unnecessary external stat calls for
non-partition rows; move the majorMinorLookup.apply(...) invocation inside the
guard that builds partitions (the if (split.length > 4) block) and use its
returned Pair<Integer,Integer> when constructing the HWPartition (same block
that calls new HWPartition(...)) so only rows that become partitions trigger the
major/minor lookup (referencing majorMinorLookup.apply, the split.length > 4
guard, and the HWPartition construction).

41-48: 💤 Low value

Fix/clarify fallback behavior in Disklabel.getDiskParams when disklabel returns only header metadata

Disklabel.getDiskParams falls back to parseDfFallback whenever disklabel -n yields an empty partition list (result.getD().isEmpty()). Even if parseDiskParams successfully parsed header fields (label, duid, and total size from total sectors:/bytes/sector:), parseDfFallback replaces the whole quartet with Constants.UNKNOWN/0L, discarding that metadata. OpenBSD and NetBSD both route through this same shared Disklabel.getDiskParams, so the all-or-nothing fallback behavior is consistent across both OSes.

If the goal is “use df only to fill missing partitions”, consider preserving the label/duid/size from the disklabel parse and only swapping the partition list when it’s empty.

🤖 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-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java` around
lines 41 - 48, getDiskParams currently discards any header metadata parsed by
parseDiskParams (label/duid/size) whenever result.getD().isEmpty() by calling
parseDfFallback which returns a whole Quartet of UNKNOWN/0L; change this so that
when parseDiskParams returns a Quartet with non-empty header fields but an empty
partition list, you call parseDfFallback only to obtain partitions and then
construct/return a new Quartet combining the original label/duid/size from the
parseDiskParams result with the partition list from parseDfFallback instead of
replacing the entire Quartet; update the logic around result =
parseDiskParams(...), the result.getD().isEmpty() branch, and the use of
parseDfFallback so only the D element (List<HWPartition>) is replaced when
appropriate.
🤖 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-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java`:
- Around line 1-4: Update the license header in package-info.java to match
Spotless’ template by removing the "(c)" so it reads "Copyright 2026 The OSHI
Project Contributors" (aligning with the $YEAR format used elsewhere) and keep
the SPDX-License-Identifier: MIT line; modify the header in the
package-info.java file containing the BSD disk driver package declaration to
exactly match the template used by other files like Disklabel.java.

In
`@oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java`:
- Around line 48-58: getPowerSources() currently calls
Systat.queryPowerSourceNames() then repeatedly calls getPowerSource(name) which
invokes Systat.queryBatteryFields(name), causing "systat -ab sensors" to run for
each battery; instead run the sensor command once and reuse its parsed output:
modify Systat to expose a single method (e.g., querySensorLines() or the command
string) that returns all lines or parsed blocks, call that once in
getPowerSources(), use existing parse* helpers to build BatteryFields for each
name, and change getPowerSource(String) to accept parsed data (or lookup into
the cached parse) so Systat.queryBatteryFields(name) is not re-invoked per power
source.

In
`@oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.java`:
- Around line 48-58: getPowerSources currently calls
Systat.queryPowerSourceNames() then calls Systat.queryBatteryFields(name) for
each name, causing Systat (systat -ab sensors) to be run N+1 times; instead run
the systat command once, capture its output, parse names and battery fields from
that single output, and pass the parsed data into
getPowerSource/getPowerSources. Concretely: modify Systat to expose a method
that returns the raw systat output (or a parsed token list), call that once in
OpenBsdPowerSource.getPowerSources, derive the list of names from that captured
output (instead of calling queryPowerSourceNames()), and change or add versions
of queryBatteryFields/parseBatteryFields that take the captured output (or
parsed tokens) so getPowerSource(name) uses the in-memory output to build
BatteryFields without spawning the command repeatedly.

---

Outside diff comments:
In `@oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java`:
- Around line 52-62: parseOpenFiles currently always subtracts 1 for a header
and can return -1 for empty input; change parseOpenFiles in FstatUtil so it
guards the header subtraction (e.g., only subtract when fd > 0 or when
fstatLines.size() > 1) and return 0 instead of negative values, ensuring callers
like getOpenFiles(int) and OpenBsdOSProcess.getOpenFiles() never see a negative
count; also update the FstatUtilTest.testParseOpenFilesEmpty expectation from
-1L to 0L.

---

Nitpick comments:
In `@oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java`:
- Around line 86-91: The code calls majorMinorLookup.apply(diskName, name)
before checking split.length > 4, causing unnecessary external stat calls for
non-partition rows; move the majorMinorLookup.apply(...) invocation inside the
guard that builds partitions (the if (split.length > 4) block) and use its
returned Pair<Integer,Integer> when constructing the HWPartition (same block
that calls new HWPartition(...)) so only rows that become partitions trigger the
major/minor lookup (referencing majorMinorLookup.apply, the split.length > 4
guard, and the HWPartition construction).
- Around line 41-48: getDiskParams currently discards any header metadata parsed
by parseDiskParams (label/duid/size) whenever result.getD().isEmpty() by calling
parseDfFallback which returns a whole Quartet of UNKNOWN/0L; change this so that
when parseDiskParams returns a Quartet with non-empty header fields but an empty
partition list, you call parseDfFallback only to obtain partitions and then
construct/return a new Quartet combining the original label/duid/size from the
parseDiskParams result with the partition list from parseDfFallback instead of
replacing the entire Quartet; update the logic around result =
parseDiskParams(...), the result.getD().isEmpty() branch, and the use of
parseDfFallback so only the D element (List<HWPartition>) is replaced when
appropriate.
🪄 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: 1ccaf3c4-8837-4d10-81c2-ba5c920e1035

📥 Commits

Reviewing files that changed from the base of the PR and between 4cc4ee6 and 494aed2.

📒 Files selected for processing (27)
  • oshi-core/src/main/java/oshi/driver/unix/bsd/Systat.java
  • oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java
  • oshi-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java
  • oshi-core/src/main/java/oshi/driver/unix/bsd/package-info.java
  • oshi-core/src/main/java/oshi/driver/unix/netbsd/disk/Disklabel.java
  • oshi-core/src/main/java/oshi/driver/unix/netbsd/disk/package-info.java
  • oshi-core/src/main/java/oshi/driver/unix/openbsd/disk/Disklabel.java
  • oshi-core/src/main/java/oshi/driver/unix/openbsd/disk/package-info.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdSensors.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdSensors.java
  • oshi-core/src/main/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/freebsd/ProcstatUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/netbsd/FstatUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java
  • oshi-core/src/test/java/module-info.test
  • oshi-core/src/test/java/oshi/driver/unix/bsd/SystatTest.java
  • oshi-core/src/test/java/oshi/driver/unix/bsd/disk/DisklabelTest.java
  • oshi-core/src/test/java/oshi/driver/unix/netbsd/disk/DisklabelTest.java
  • oshi-core/src/test/java/oshi/driver/unix/openbsd/disk/DisklabelTest.java
  • oshi-core/src/test/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/platform/unix/freebsd/ProcstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/platform/unix/netbsd/FstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/platform/unix/openbsd/FstatUtilTest.java
💤 Files with no reviewable changes (6)
  • oshi-core/src/test/java/oshi/driver/unix/openbsd/disk/DisklabelTest.java
  • oshi-core/src/main/java/oshi/driver/unix/openbsd/disk/package-info.java
  • oshi-core/src/main/java/oshi/driver/unix/netbsd/disk/package-info.java
  • oshi-core/src/test/java/oshi/driver/unix/netbsd/disk/DisklabelTest.java
  • oshi-core/src/main/java/oshi/driver/unix/openbsd/disk/Disklabel.java
  • oshi-core/src/main/java/oshi/driver/unix/netbsd/disk/Disklabel.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdSensors.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdSensors.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java
🔇 Additional comments (16)
oshi-core/src/test/java/oshi/util/platform/unix/openbsd/FstatUtilTest.java (1)

53-58: This test pins the -1L return for empty input, which is the latent negative-count bug flagged at the root cause in FstatUtil.parseOpenFiles. Once that method is guarded, update this assertion to is(0L).

oshi-core/src/main/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtil.java (1)

64-82: LGTM!

Also applies to: 101-121

oshi-core/src/main/java/oshi/util/platform/unix/freebsd/ProcstatUtil.java (1)

32-51: LGTM!

Also applies to: 60-78, 87-106

oshi-core/src/main/java/oshi/util/platform/unix/netbsd/FstatUtil.java (1)

33-50: LGTM!

Also applies to: 60-75

oshi-core/src/test/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtilTest.java (1)

32-91: LGTM!

oshi-core/src/test/java/oshi/util/platform/unix/freebsd/ProcstatUtilTest.java (1)

33-98: LGTM!

oshi-core/src/test/java/oshi/util/platform/unix/netbsd/FstatUtilTest.java (1)

29-73: LGTM!

oshi-core/src/test/java/module-info.test (1)

27-30: LGTM!

Also applies to: 36-36

oshi-core/src/main/java/oshi/driver/unix/bsd/Systat.java (1)

35-151: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdSensors.java (1)

13-39: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdSensors.java (1)

13-39: LGTM!

oshi-core/src/test/java/oshi/driver/unix/bsd/SystatTest.java (1)

29-154: LGTM!

oshi-core/src/main/java/oshi/driver/unix/bsd/package-info.java (1)

1-4: Same license header format concern as in oshi/driver/unix/bsd/disk/package-info.java (Copyright (c) 2026 vs the project's Copyright 2026 The OSHI Project Contributors).

oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHWDiskStore.java (1)

17-17: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java (1)

17-17: LGTM!

oshi-core/src/test/java/oshi/driver/unix/bsd/disk/DisklabelTest.java (1)

46-160: LGTM!

Comment on lines +1 to +4
/*
* Copyright (c) 2026 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n '^ \* Copyright' --type=java | sed -E 's/[0-9]{4}(-[0-9]{4})?//' | sort | uniq -c | sort -rn

Repository: oshi/oshi

Length of output: 50366


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Inspect the exact header in the file under review
FILE="oshi-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java"
echo "---- $FILE (lines 1-10) ----"
sed -n '1,10p' "$FILE" || true

# 2) Count how many Java files use "(c)" vs not (based on the "Copyright" header line)
echo "---- Count: Java files with 'Copyright (c)' ----"
rg -n --type java '^ \* Copyright \(c\)' . | wc -l

echo "---- Count: Java files with 'Copyright' but NOT '(c)' ----"
rg -n --type java '^ \* Copyright(?! \(c\))' . | wc -l

# 3) Find likely license/header enforcement configuration
echo "---- Search build for license/header enforcement ----"
rg -n --hidden --glob '!.git/**' -S \
  'spotless|license|rat|license-maven-plugin|maven-enforcer-plugin|header|copyright' \
  pom.xml build.gradle* build.gradle.kts* settings.gradle* settings.gradle.kts* .github . | head -n 200

Repository: oshi/oshi

Length of output: 766


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Recompute counts without lookaround
TOTAL=$(rg -n --type java '^ \* Copyright' . | wc -l)
WITHC=$(rg -n --type java '^ \* Copyright \(c\)' . | wc -l)
NONC=$((TOTAL-WITHC))

echo "---- Count: Java files with 'Copyright' (any) ----"
echo "$TOTAL"
echo "---- Count: Java files with 'Copyright (c)' ----"
echo "$WITHC"
echo "---- Derived: Java files with 'Copyright' but NOT '(c)' ----"
echo "$NONC"

# Locate build/header enforcement configuration
echo "---- Search build for header/license enforcement ----"
rg -n --hidden -S \
  'spotless|license|rat|license-maven-plugin|license-header|header-check|enforcer|maven-enforcer-plugin|apache-rat|licenseHeader' \
  pom.xml build.gradle* build.gradle.kts* settings.gradle* settings.gradle.kts* \
  .github/workflows . | head -n 200

Repository: oshi/oshi

Length of output: 21502


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- pom.xml: Spotless licenseHeader section (context) ----"
# Print around the known lines from earlier grep output
sed -n '440,560p' pom.xml

echo "---- config/license-header.txt ----"
ls -la config/license-header.txt || true
sed -n '1,120p' config/license-header.txt || true

Repository: oshi/oshi

Length of output: 6426


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java"
echo "---- $FILE (lines 1-10) ----"
sed -n '1,10p' "$FILE" || true

Repository: oshi/oshi

Length of output: 359


Fix the license header in this file to match Spotless’ template

pom.xml configures Spotless to enforce config/license-header.txt, whose expected header is * Copyright $YEAR The OSHI Project Contributors (no (c)). This file uses * Copyright (c) 2026 The OSHI Project Contributors, so the header check may fail—update it to match the template (and align the year format with other BSD disk headers like Disklabel.java).

🤖 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-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java` around
lines 1 - 4, Update the license header in package-info.java to match Spotless’
template by removing the "(c)" so it reads "Copyright 2026 The OSHI Project
Contributors" (aligning with the $YEAR format used elsewhere) and keep the
SPDX-License-Identifier: MIT line; modify the header in the package-info.java
file containing the BSD disk driver package declaration to exactly match the
template used by other files like Disklabel.java.

…abel

- Systat: add public querySensorLines() returning the raw `systat -ab sensors`
  output; the existing single-purpose query* methods now route through it.
  OpenBsdPowerSource and NetBsdPowerSource take the lines once in
  getPowerSources() and pass them to a per-battery getPowerSource(name, lines)
  that uses Systat.parseBatteryFields, eliminating the N+1 systat invocations
  the previous wiring produced when multiple batteries were present.
- FstatUtil (openbsd) parseOpenFiles: guard the header-row subtraction so
  empty or single-row input returns 0 instead of -1. Callers
  (OpenBsdOSProcess.getOpenFiles / NetBsdOSProcess.getOpenFiles) propagate the
  return value directly. Existing test updated.
- Disklabel (bsd): move the major/minor lookup inside the
  split.length > 4 (parseDiskParams) and split.length > 5 (parseDfFallback)
  guards so non-partition rows don't trigger a stat(1) call.
- Disklabel.getDiskParams: when disklabel returned header metadata but no
  partitions, preserve the label/DUID/size and replace only the partition
  list with the df fallback result, instead of returning the entirely-UNKNOWN
  fallback Quartet.
@dbwiddis
dbwiddis merged commit 6f54ed9 into oshi:master May 31, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the refactor/bsd-shared-parsers branch May 31, 2026 19:39
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