Repository navigation
Differentially test the pre-Windows-10 physical-memory fallback path - #3454
Conversation
The pre-Windows-10 branch of WindowsGlobalMemory.getPhysicalMemory() has never run on CI (runners are Windows 10+), so its legacy Win32_PhysicalMemory query and field mapping have gone untested through several refactors. The recent dedup made the version gate an overridable isWindows10OrGreater() hook, so the legacy path can now be forced against the real system without mocking. Drop `final` from WindowsGlobalMemoryJNA so a test can subclass it and override only the version gate, inheriting the genuine query hooks. Add a Windows-only differential test that runs the real WMI query with the gate forced both ways and asserts the legacy and modern results agree bank-for-bank on every schema-independent field (bank label, capacity, speed, manufacturer, part number, serial number); memoryType is excluded because the two schemas resolve it differently. Results are sorted before comparison so WMI row order can't flake it, and empty-bank runners still exercise the legacy branch. A red result on the Windows runner means the legacy path diverged from the modern one -- exactly the class of bug this is meant to surface.
📝 WalkthroughWalkthrough
ChangesWindows memory parity
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
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-core/src/test/java/oshi/hardware/platform/windows/WindowsGlobalMemoryLegacyTest.java`:
- Around line 30-31: Update the BY_BANK comparator to use null-safe ordering for
both PhysicalMemory::getBankLabel and PhysicalMemory::getSerialNumber, wrapping
each natural-order key comparator with nullsFirst. Preserve the existing
capacity comparison and comparator ordering.
🪄 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: 2e3b1ceb-30e4-4fec-9693-3539f470cf8c
📒 Files selected for processing (2)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.javaoshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGlobalMemoryLegacyTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (16)
- GitHub Check: CodeRabbit
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 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/WindowsGlobalMemoryJNA.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-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
🔇 Additional comments (2)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java (1)
26-31: LGTM!oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGlobalMemoryLegacyTest.java (1)
53-71: LGTM!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3454 +/- ##
=========================================
Coverage 74.61% 74.62%
Complexity 76 76
=========================================
Files 584 584
Lines 21923 21923
Branches 3679 3679
=========================================
+ Hits 16357 16359 +2
+ Misses 3529 3518 -11
- Partials 2037 2046 +9
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:
|
Summary
The pre-Windows-10 branch of
WindowsGlobalMemory.getPhysicalMemory()(theWin32_PhysicalMemoryquery with the pre-10MemoryTypefield, resolved viamemoryType()instead ofsmBiosMemoryType()) has never executed on CI — the runners are all Windows 10+, so thatelsebranch is dead on CI and its legacy query/field-mapping has drifted through several refactors untested since it was written on a Win7 VM years ago.The recent memory dedup (#3453) incidentally made this testable: the version check is now an overridable
protected isWindows10OrGreater()hook rather than an inlined staticVersionHelpersread, so the legacy path can be forced against the real system without mocking a static native call.Changes
WindowsGlobalMemoryJNA: droppedfinal(one word + a javadoc note) so a test can subclass it and override only the version gate, inheriting the genuine query hooks.WindowsGlobalMemoryLegacyTest(new,@EnabledOnOs(WINDOWS)): builds the real class twice withisWindows10OrGreater()forcedfalseandtrue, runs the real WMI query both ways, and asserts the legacy and modern results agree bank-for-bank on every schema-independent field — bank label, capacity, clock speed, manufacturer, part number, serial number.memoryTypeis intentionally excluded (the two schemas legitimately resolve it differently). Lists are sorted before comparison so WMI row order can't flake it; a runner reporting no banks still exercises the legacy branch.Why differential (not fabricated tables)
The goal isn't coverage for its own sake — it's to exercise the real legacy query/parse on real hardware and catch a rotted path. Feeding canned
WmiResulttables would only test the parser. Forcing the gate and diffing legacy-vs-modern on the same machine catches a broken legacy query (wrong field, wrong parse) as a concrete divergence.A red result on the Windows runner is the intended signal that the legacy path diverged and needs a fix (either the path itself, or narrowing the comparison if some field legitimately differs pre-10).
Testing
[S] Disabled)Pattern
Establishes a reusable approach for the consistency arc: seam the version/capability gate, then differential-test the legacy path against real data — to reapply on the Windows CPU counter-set selection (
ProcessorvsProcessorInformation) and the 32-bit uptime wrap when those subsystems are touched.Summary by CodeRabbit
Bug Fixes
Tests