Repository navigation
Dedup the LogicalVolumeGroup bindings - #3546
Conversation
Windows was the only platform whose volume group class had no common base, so its two bindings each carried a full copy of the Storage Spaces correlation: parse the object IDs out of four MSFT_Storage queries, then match pools to their physical and virtual disks by GUID substring. The queries return WmiResult, which is already backend-neutral, so only the COM plumbing that runs them actually differs. A new WindowsLogicalVolumeGroup base holds the correlation and takes the four results plus a factory; the bindings keep the version gate, the COM init, and the queries themselves. They drop from 162 and 145 lines to 61 and 60. Linux already had a base for the pvs parsing, but both bindings still repeated the device-mapper filtering, the sysfs slaves scan and the volume group assembly around their own udev enumeration. The bindings now return the udev attributes of each block device as a carrier and the base does the rest, which is the same boundary the USB enumeration uses. Unifies one divergence between the Linux bindings: JNA looked the physical volume set up with get, FFM with getOrDefault and an empty default. Both maps are populated together so the null could not be reached, but a null set would throw in the immutable-copy constructor rather than degrade, so the defaulting form is kept. Both shared methods are pure, so they are now covered without Windows, Linux or LVM: the Storage Spaces correlation against stubbed WmiResults, and the volume group assembly against a temporary directory standing in for sysfs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (6)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
🔇 Additional comments (2)
📝 WalkthroughWalkthroughShared Linux and Windows implementations now assemble logical volume groups from platform-specific discovery data. FFM and JNA bindings collect native data and delegate construction to these implementations, with tests covering correlation and edge cases. ChangesLogical volume group assembly
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant LinuxBinding
participant LinuxBuilder
participant Sysfs
LinuxBinding->>LinuxBuilder: pass enumerated udev devices
LinuxBuilder->>Sysfs: read LVM slave devices
Sysfs-->>LinuxBuilder: return physical-volume paths
LinuxBuilder-->>LinuxBinding: return logical volume groups
sequenceDiagram
participant WindowsBinding
participant WMI
participant WindowsBuilder
WindowsBinding->>WMI: query Storage Spaces data
WMI-->>WindowsBinding: return pools and disk relationships
WindowsBinding->>WindowsBuilder: pass WMI results
WindowsBuilder-->>WindowsBinding: return correlated logical volume groups
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroupTest.java (1)
191-203: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert the "no correlation" outcome, not just that nothing threw.
The test name claims degradation to no correlation, but only size and name are checked. Asserting empty volumes pins the actual contract and would catch a regression where the unmatched ObjectId became an empty string (which
containsmatches against everything).💚 Proposed assertions
assertThat(lvgs, hasSize(1)); assertThat(lvgs.get(0).getName(), is("Pool1")); + assertThat("An unparseable pool ObjectId correlates to nothing", lvgs.get(0).getPhysicalVolumes(), + is(empty())); + assertThat(lvgs.get(0).getLogicalVolumes().keySet(), is(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-common/src/test/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroupTest.java` around lines 191 - 203, Update testUnparseableObjectIdsDoNotThrow to assert that the resulting LogicalVolumeGroup has no correlated volumes, in addition to the existing size and name checks. Verify the group's volumes collection is empty so an invalid OBJECTID cannot accidentally match all entries.
🤖 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/test/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroupTest.java`:
- Around line 191-203: Update testUnparseableObjectIdsDoNotThrow to assert that
the resulting LogicalVolumeGroup has no correlated volumes, in addition to the
existing size and name checks. Verify the group's volumes collection is empty so
an invalid OBJECTID cannot accidentally match all entries.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 92beed03-095a-4fa4-8283-c7566fe0eae9
📒 Files selected for processing (8)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxLogicalVolumeGroup.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroup.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxLogicalVolumeGroupTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroupTest.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout. (5)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (3)
📚 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/windows/WindowsLogicalVolumeGroup.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxLogicalVolumeGroup.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/windows/WindowsLogicalVolumeGroup.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupJNA.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupFFM.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxLogicalVolumeGroup.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
📚 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/windows/WindowsLogicalVolumeGroupJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
🔇 Additional comments (11)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroup.java (1)
35-50: LGTM!Also applies to: 78-161
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupJNA.java (1)
23-26: LGTM!Also applies to: 47-51
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupFFM.java (1)
23-23: 📐 Maintainability & Code QualityJPMS export is already present.
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxLogicalVolumeGroup.java (2)
7-21: LGTM!
76-172: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java (2)
12-50: LGTM!
72-83: LGTM!oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java (2)
9-46: LGTM!
55-75: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxLogicalVolumeGroupTest.java (2)
11-88: LGTM!
90-159: LGTM!
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3546 +/- ##
============================================
+ Coverage 79.18% 79.31% +0.12%
Complexity 3762 3762
============================================
Files 703 704 +1
Lines 24265 24320 +55
Branches 4038 4050 +12
============================================
+ Hits 19214 19289 +75
+ Misses 2869 2841 -28
- Partials 2182 2190 +8
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:
|
Pool members are matched by substring, and every string contains the empty one, so an empty pool ObjectId matched every entry rather than none. WmiUtil maps an absent property to an empty string, so a storage pool whose ObjectId did not come back would be reported as owning every physical disk and every virtual disk on the system. An unparseable ObjectId was already safe, because the raw value is kept when the regex does not match and a non-empty value still fails the substring test. Only the empty case was wrong, so the guard is on that. This is the same trap the graphics card audit found twice, where an empty candidate or an empty needle matched everything. Asserting the correlation is empty, rather than only that the group exists, is what exposed it; the unparseable-ObjectId test now checks that too.
CodeQL Code Quality reported seven java/index-out-of-bounds findings (severity error) across the two test files added in #3543 and #3546. Each finding is the same shape: a private varargs helper walks its arguments in fixed-size groups, striding by two or three, but bounds the loop on the first index of the group rather than the last. Reading namesAndIds[i + 1] under a loop guarded only by i < namesAndIds.length runs off the end whenever the caller passes a partial group. Unlike the useless-null-check and dereferenced-value-may-be-null findings on these files, this one is not a false positive. Every call site today passes a complete multiple, so nothing can throw as written, but the helpers make no such guarantee and the finding will resurface each time the files move. Bounding each loop on the last index it reads is what CodeQL's range analysis needs to see, and it turns a would-be ArrayIndexOutOfBoundsException into one fewer row for a caller that miscounts -- which a test's own assertions will catch immediately. The two production stride loops were checked and left alone: ParseUtil.hexStringToByteArray already rejects odd-length input with an explicit (len & 0x1) != 0 guard, and HkeyPerformanceDataUtil.buildCounterIndexMap starts at i = 1 and reads backwards to i - 1, so both indices are always in range. Neither was flagged. Test-only, so no CHANGELOG entry.
Audit item 12. 8 files, 253+/272−.
Windows — the bulk of it
Windows was the only platform whose volume group class had no common base, so both bindings carried a full copy of the Storage Spaces correlation: pull object IDs out of four
MSFT_Storagequeries, then match pools to their physical and virtual disks by GUID substring.The queries return
WmiResult, which is already backend-neutral, so the only real difference was the COM plumbing that runs them. NewWindowsLogicalVolumeGroupbase takes the four results plus a factory (the #3452/#3544 pattern); the bindings keep the version gate, COM init/uninit, the queries, and their own exception type.WindowsLogicalVolumeGroupJNAWindowsLogicalVolumeGroupFFMThe "query storage pools first so we can skip the other three queries when there are none" short-circuit is preserved — the early return still happens before the other queries are issued.
Linux
Linux already had a base for the
pvsparsing, but both bindings still repeated the device-mapper filtering, the sysfsslavesscan and the group assembly around their own udev enumeration. The bindings now return each block device's udev attributes as a carrier and the base does the rest — the same hook boundary the USB enumeration uses (#3448), since the udev call itself is irreducibly different (JNAUdevContextvs FFMMemorySegment).One divergence unified
JNA looked the physical volume set up with
physicalVolumesMap.get(...), FFM withgetOrDefault(..., emptySet()). Both maps arecomputeIfAbsent-populated in the same block so the null was unreachable — but a null set throws inAbstractLogicalVolumeGroup's immutable-copy constructor rather than degrading, so the defaulting form is the one kept.Tests
Both shared methods are pure, so they are now covered without Windows, Linux, or LVM configured — paths that were previously unreachable in CI at all, since Storage Spaces needs pooled disks and LVM needs volume groups.
WindowsLogicalVolumeGroupTeststubs the fourWmiResults: correlation of a pool with its disks and volumes, two pools not bleeding into each other (the substring match this logic exists to get right), an unknown physical disk being skipped rather than yieldingnull @ null, unparseable object IDs degrading instead of throwing, and multiple volumes in one pool. One test pins the fixture itself against the production regexes, so a fixture that stopped matching can't leave the others passing vacuously.LinuxLogicalVolumeGroupTestgains assembly coverage using a@TempDiras a stand-in for sysfs: slaves-directory expansion, two volumes sharing a group, non-LVM devices filtered (plain disk, LUKS-owned device-mapper node, blank/null udev properties), a missing slaves directory still yielding the group, andpvsresults merged with rather than replaced by the slaves scan.Full gate green on
oshi-common,oshi-core,oshi-core-ffmplus a clean full-reactorinstall, 0 tests failed. Windows and Linux runtime paths are CI-only;pr.yamlruns both automatically.No CHANGELOG — no user-observable behavior change.
Summary by CodeRabbit