Skip to content

Extract Mac/Windows NetworkParams common bases - #3457

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-networkparams-mac-windows
Jul 13, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-networkparams-mac-windows

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Continues Item 6 of the cross-OS dedup audit (NetworkParams half). Mac and Windows were the only platforms whose NetworkParams still lacked a common base — Linux/AIX/FreeBSD/NetBSD/OpenBSD/Solaris all have one — so their JNA and FFM twins each carried a full copy of the command-line default-gateway lookups. This adds the two missing bases, mirroring the Windows-memory dedup (#3453).

Changes

  • New MacNetworkParams (software.common.os.mac): holds getIpv4DefaultGateway/getIpv6DefaultGateway (the route -n get default and netstat -nr parsing) + the route constants. Mac JNA/FFM twins extend it and keep only their native getDomainName/getHostName (getaddrinfo/gethostname).
  • New WindowsNetworkParams (software.common.os.windows): holds getIpv4DefaultGateway/getIpv6DefaultGateway (the route print parsing). Windows JNA/FFM twins extend it and keep native getDomainName/getDnsServers/getHostName (GetComputerNameEx/GetNetworkParams).
  • The twins' super.getHostName() fallbacks still resolve to AbstractNetworkParams — the new bases don't override it.

Both target packages were already declared and exported in module-info, so no module changes were needed.

~96 lines of identical command-line gateway/route code collapsed from two copies each into one base (net raw count roughly flat since the two base files are new).

Behavior

No user-facing change — same gateway/route parsing, only relocated; the native hostname/DNS calls stay per-backend.

Testing

  • spotless / checkstyle / forbiddenapis / javadoc: clean
  • Clean full-reactor install: BUILD SUCCESS, 0 tests failed
  • NativeComparisonTest.networkParams() JNA==FFM comparison: passes on macOS

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of IPv4 and IPv6 default gateways on macOS and Windows.
    • Standardized gateway lookup across supported native integration options.
    • Improved IPv6 gateway parsing by removing interface suffixes from detected addresses.
    • Preserved existing hostname, domain, and DNS information retrieval.

Mac and Windows were the two platforms whose NetworkParams still lacked a
common base (unlike Linux/AIX/BSD/Solaris), so their JNA and FFM twins each
duplicated the command-line default-gateway lookups. Add the missing bases and
hoist that shared logic.

MacNetworkParams holds getIpv4/getIpv6DefaultGateway (route / netstat parsing);
the Mac twins keep only their native getDomainName/getHostName (getaddrinfo /
gethostname). WindowsNetworkParams holds getIpv4/getIpv6DefaultGateway (route
print parsing); the Windows twins keep native getDomainName/getDnsServers/
getHostName. The twins' super.getHostName() fallbacks still resolve to
AbstractNetworkParams, which the new bases do not override.

No user-facing change; NetworkParams JNA==FFM comparison passes.
@coderabbitai

coderabbitai Bot commented Jul 13, 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: 8a2be78f-5259-406b-9782-75f2c275886a

📥 Commits

Reviewing files that changed from the base of the PR and between 04942e0 and b625d56.

📒 Files selected for processing (6)
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsNetworkParams.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsNetworkParamsFFM.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • 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: Test JDK 25, FreeBSD (+ JNA==FFM)
  • 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/software/common/os/windows/WindowsNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacNetworkParams.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/software/common/os/windows/WindowsNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacNetworkParams.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsNetworkParamsFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.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/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java
🔇 Additional comments (6)
oshi-common/src/main/java/oshi/software/common/os/mac/MacNetworkParams.java (1)

1-50: LGTM!

oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java (1)

11-11: LGTM!

Also applies to: 22-33, 71-72

oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java (1)

23-39: LGTM!

Also applies to: 89-90

oshi-common/src/main/java/oshi/software/common/os/windows/WindowsNetworkParams.java (1)

1-57: LGTM!

oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java (1)

26-32: LGTM!

Also applies to: 92-93

oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsNetworkParamsFFM.java (1)

7-11: LGTM!

Also applies to: 28-28


📝 Walkthrough

Walkthrough

macOS and Windows default-gateway lookup logic moved into shared abstract network-parameter classes. JNA and FFM implementations now inherit platform-specific gateway parsing while retaining their native hostname, domain, and DNS behavior.

Changes

Network gateway refactor

Layer / File(s) Summary
macOS gateway resolution and adapters
oshi-common/.../os/mac/MacNetworkParams.java, oshi-core/src/main/java/oshi/software/os/mac/*
Shared macOS logic parses IPv4 routes and IPv6 netstat output; JNA and FFM classes now extend MacNetworkParams and no longer duplicate gateway methods.
Windows gateway resolution and adapters
oshi-common/.../os/windows/WindowsNetworkParams.java, oshi-core/src/main/java/oshi/software/os/windows/*, oshi-core-ffm/src/main/java/oshi/software/os/windows/*
Shared Windows logic parses IPv4 and IPv6 route print output; JNA and FFM classes now extend WindowsNetworkParams and remove local route parsers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

I’m a rabbit with routes in my hat,
Mac and Windows now share where they’re at.
IPv4 hops, IPv6 too,
One common path makes gateways few.
Hop-hop—clean code springs anew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: extracting shared macOS and Windows NetworkParams base classes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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.

@codecov

codecov Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.55556% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.63%. Comparing base (04942e0) to head (b625d56).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ftware/common/os/windows/WindowsNetworkParams.java 77.77% 2 Missing and 2 partials ⚠️
.../oshi/software/common/os/mac/MacNetworkParams.java 78.57% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3457      +/-   ##
============================================
- Coverage     74.69%   74.63%   -0.06%     
  Complexity       76       76              
============================================
  Files           584      586       +2     
  Lines         21862    21838      -24     
  Branches       3671     3663       -8     
============================================
- Hits          16329    16298      -31     
- Misses         3491     3500       +9     
+ Partials       2042     2040       -2     
Flag Coverage Δ
freebsd 26.95% <0.00%> (+0.03%) ⬆️
linux 31.58% <0.00%> (+0.04%) ⬆️
macos 32.07% <36.11%> (-0.03%) ⬇️
openbsd 26.44% <0.00%> (+0.06%) ⬆️
solaris 28.43% <0.00%> (-0.03%) ⬇️
windows 39.87% <44.44%> (-0.04%) ⬇️

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

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

@dbwiddis
dbwiddis merged commit 59553d4 into oshi:master Jul 13, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the dedup-networkparams-mac-windows branch July 13, 2026 01:03
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