Repository navigation
Dedup NetworkIF native stats/model and test the Windows Vista legacy path - #3458
Conversation
…path Finishes the per-platform NetworkIF dedup begun with the enumeration hoist. Mac: updateNetworkStats was byte-identical across JNA and FFM (both map the shared IFdata POJO); hoist it and updateAttributes into MacNetworkIF with a queryIFdata(int) hook, leaving only the native display-name lookup in the twins. Linux: the vendor/model formatting was triplicated (both udev twins plus the sysfs reader); extract a formatModel(vendor, model, fallback) helper. Windows: introduce a WindowsNetworkIF base with an IfStats carrier and a queryStats() hook (the Solaris/AIX pattern), hoisting the five interface-detail getters, fields, and updateAttributes out of both twins. The JNA MIB_IFROW2 vs pre-Vista MIB_IFROW selection becomes an overridable isVistaOrGreater() seam, and WindowsNetworkIfJNA is no longer final so a test can force the legacy path. Add WindowsNetworkIfLegacyTest (Windows-only): it runs the real GetIfEntry (MIB_IFROW) query with the version gate forced off and asserts the pre-Vista path succeeds and reports the same ifType as the modern path -- catching a rotted legacy path that is otherwise dead on CI (runners are all Vista+). No user-facing change; NetworkIF JNA==FFM comparison passes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (13)
📝 WalkthroughWalkthroughThe PR centralizes Linux model formatting, moves macOS statistics mapping into a shared base flow, and adds a Windows statistics base used by JNA and FFM implementations, including legacy-path coverage. ChangesNetwork interface refactor
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant WindowsNetworkIF
participant WindowsNetworkIfJNA
participant WindowsNetworkIfFFM
participant IPHelperAPI
WindowsNetworkIF->>WindowsNetworkIfJNA: queryStats()
WindowsNetworkIfJNA->>IPHelperAPI: Query Vista or legacy interface statistics
IPHelperAPI-->>WindowsNetworkIfJNA: IfStats values
WindowsNetworkIF->>WindowsNetworkIfFFM: queryStats()
WindowsNetworkIfFFM->>IPHelperAPI: GetIfEntry2
IPHelperAPI-->>WindowsNetworkIfFFM: IfStats values
WindowsNetworkIF->>WindowsNetworkIF: update interface fields
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 #3458 +/- ##
============================================
+ Coverage 74.70% 74.74% +0.03%
- Complexity 76 2589 +2513
============================================
Files 586 587 +1
Lines 21838 21830 -8
Branches 3663 3656 -7
============================================
+ Hits 16315 16316 +1
+ Misses 3488 3475 -13
- Partials 2035 2039 +4
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-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java (1)
32-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winHoist
CONNECTOR_PRESENT_BITtoWindowsNetworkIFinstead of duplicating it here and inWindowsNetworkIfJNA.Both backends define the identical bit mask for the same native flag; this PR's stated goal is consolidating shared Windows stats logic into the common base.
♻️ Proposed refactor
- private static final byte CONNECTOR_PRESENT_BIT = 0b00000100; - public WindowsNetworkIfFFM(NetworkInterface netint) throws InstantiationException {Add the constant once in
WindowsNetworkIF(e.g.protected static final byte CONNECTOR_PRESENT_BIT = 0b00000100;) and reference it from bothWindowsNetworkIfJNAandWindowsNetworkIfFFM, removing their local copies.🤖 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-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java` at line 32, Move CONNECTOR_PRESENT_BIT into the shared WindowsNetworkIF class as a protected constant, then update WindowsNetworkIfJNA and WindowsNetworkIfFFM to reference that inherited constant and remove their duplicate declarations.oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsNetworkIF.java (1)
37-53: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
IfStatsas a mutable public-field carrier.Fine as an internal transfer object between backend query and base-class mapping; consider
finalfields set via a constructor for stronger invariants if this carrier grows further.🤖 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/windows/WindowsNetworkIF.java` around lines 37 - 53, Update the WindowsNetworkIF.IfStats transfer object to use final fields initialized through a constructor instead of mutable public fields. Ensure the constructor accepts and assigns every existing statistic, alias, and operational-status value, and update its creation sites accordingly while preserving the current backend-to-base-class mapping.
🤖 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/windows/WindowsNetworkIF.java`:
- Around line 37-53: Update the WindowsNetworkIF.IfStats transfer object to use
final fields initialized through a constructor instead of mutable public fields.
Ensure the constructor accepts and assigns every existing statistic, alias, and
operational-status value, and update its creation sites accordingly while
preserving the current backend-to-base-class mapping.
In
`@oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java`:
- Line 32: Move CONNECTOR_PRESENT_BIT into the shared WindowsNetworkIF class as
a protected constant, then update WindowsNetworkIfJNA and WindowsNetworkIfFFM to
reference that inherited constant and remove their duplicate declarations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4edfe35d-545b-4583-90a0-2acae092be93
📒 Files selected for processing (11)
config/checkstyle-suppressions.xmloshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsNetworkIF.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.javaoshi-core/src/test/java/oshi/hardware/platform/windows/WindowsNetworkIfLegacyTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (13)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 26, macos-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 21, macos-latest
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 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/linux/LinuxNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.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/linux/LinuxNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsNetworkIF.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.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/linux/LinuxNetworkIFJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java
🔇 Additional comments (13)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java (3)
36-36: 📐 Maintainability & Code Quality
CONNECTOR_PRESENT_BITis duplicated inWindowsNetworkIfFFM.See the comment on
WindowsNetworkIfFFM.javaline 32 — this constant is redeclared identically there. Given this PR's goal of hoisting shared Windows stats fields intoWindowsNetworkIF, consider moving it to the base class.
19-31: LGTM!
52-117: Vista/legacy field mapping verified correct.Cross-checked against the pre-refactor merged
WindowsNetworkIFimplementation; field mappings, unsigned-widening, and "closest proxy" semantics forcollisions/inDropsare preserved unchanged.oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java (1)
50-71: LGTM!oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFJNA.java (1)
31-44: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java (1)
37-55: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java (1)
48-83: LGTM!config/checkstyle-suppressions.xml (1)
93-96: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.java (1)
8-76: LGTM!oshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.java (1)
68-71: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.java (1)
72-75: LGTM!oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsNetworkIfLegacyTest.java (1)
1-65: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsNetworkIF.java (1)
32-35: 🩺 Stability & AvailabilityNo change needed: constructor initialization is safe here
updateAttributes()is called from the base constructor, butWindowsNetworkIfJNA.queryStats()andWindowsNetworkIfFFM.queryStats()don’t depend on subclass instance state, and the test-onlyLegacyNetworkIfoverride only flips a version gate. No action needed.> Likely an incorrect or invalid review comment.
The connector-present flag bit was declared identically in both the JNA and FFM Windows NetworkIF subclasses. Move it to the shared WindowsNetworkIF base as a protected constant and reference the inherited value.
Summary
Finishes the NetworkIF half of Item 6 — the per-platform native
updateAttributes/model dedup that the enumeration-loop hoist (#3455) left behind.Changes
updateNetworkStats(Map<Integer,IFdata>)was byte-identical across the JNA and FFM twins (both map the sharedIFdataPOJO to fields). Hoist it andupdateAttributesintoMacNetworkIFwith aqueryIFdata(int)hook; the twins keep only their native display-name lookup."vendor model"/"model"/ fallback) was triplicated across both udev twins and the sysfs reader. Extract a sharedformatModel(vendor, model, fallback)helper intoLinuxNetworkIF.WindowsNetworkIFbase with anIfStatscarrier and aqueryStats()hook (the Solaris/AIX pattern), hoisting the five interface-detail getters, fields, andupdateAttributesout of both twins. The JNAMIB_IFROW2(Vista+) vs pre-VistaMIB_IFROWselection becomes an overridableisVistaOrGreater()seam, andWindowsNetworkIfJNAis no longerfinalso a test can force the legacy path.WindowsNetworkIF's publicIfStatsPOJO to the checkstyleVisibilityModifiersuppressions (same as Solaris/AIXIfStats).Vista legacy test
WindowsNetworkIfLegacyTest(Windows-only) forcesisVistaOrGreater()off and runs the realGetIfEntry(MIB_IFROW) query against every interface, asserting the pre-Vista path succeeds for at least one and reports the sameifTypeas the modernMIB_IFROW2path. OnlyifTypeis compared — the byte/packet counters legitimately differ (pre-Vista uses unsigned 32-bit counters that wrap) and physical-medium/alias/oper-status aren't in the legacy struct. This is the #3454 pattern applied to a branch that's been dead on CI for ~15 years; a red result here means we found a real bug in that path.Behavior
No user-facing change. Net raw LOC is up (+120) because the new Windows base scaffolding + the 65-line legacy test are additions; the duplication (Mac stats ×2, Linux format ×3, Windows getters/updateAttributes ×2) is collapsed to single-source.
Testing
install: BUILD SUCCESS, 0 tests failedNativeComparisonTest.networkIfUpdateAttributes()JNA==FFM: passes on macOSSummary by CodeRabbit
New Features
Bug Fixes
Tests