Repository navigation
Read the OpenBSD host name natively - #3566
Conversation
OpenBSD had no getHostName() override, so it fell through to AbstractNetworkParams, which calls InetAddress.getLocalHost(). That resolves the name rather than just reading it, so on a host whose hostname is not resolvable -- routine in a container, or with no /etc/hosts entry -- it throws UnknownHostException, degrades to getLoopbackAddress() and reports "localhost" instead of the real name. It can also block on a DNS timeout. gethostname(2) is a plain syscall with neither failure mode. Every other platform already prefers the native call and keeps the JDK lookup as its fallback. OpenBSD now does the same, following the FreeBSD shape: OpenBsdNetworkParams becomes abstract with a queryHostName() hook and the prefer-native-fall-back-to-super override, and thin JNA and FFM subclasses supply the binding. getNetworkParams() moves from the shared OS base to the two backend subclasses, which is what lets the two differ. The FFM half only became possible with #3565: OpenBSD never bound gethostname itself, and inherits it from PosixLibcFunctions. NetBSD is deliberately left alone. Its OS class is concrete with no FFM subclass and there is no NetBsdLibcFunctions at all, because pkgsrc has no JDK 25 and its FFM backend takes the no-native route on purpose. Giving it a native host name would mean building that whole layer for one function; it stays on the JDK path, which cannot break when JDK 25 does arrive. Tracked on #3348. DragonFly BSD needs nothing: it returns FreeBsdNetworkParams{JNA,FFM} and already has the native call. OpenBSD is the best-covered of the three for this change. CI runs it on JDK 25 with aggregate coverage, so both backends exercise the new path on the next run -- unlike DragonFly, whose FFM code is untested on platform because its runner is JDK 21.
📝 WalkthroughWalkthroughOpenBSD host names now use native ChangesOpenBSD hostname lookup
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant OpenBsdOperatingSystemFFM
participant OpenBsdNetworkParamsFFM
participant OpenBSD_gethostname
OpenBsdOperatingSystemFFM->>OpenBsdNetworkParamsFFM: getNetworkParams()
OpenBsdNetworkParamsFFM->>OpenBsdNetworkParamsFFM: getHostName()
OpenBsdNetworkParamsFFM->>OpenBSD_gethostname: gethostname(buffer, HOST_NAME_MAX + 1)
OpenBSD_gethostname-->>OpenBsdNetworkParamsFFM: status and hostname bytes
OpenBsdNetworkParamsFFM-->>OpenBsdOperatingSystemFFM: decoded host name or fallback
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 #3566 +/- ##
============================================
- Coverage 79.44% 79.39% -0.06%
- Complexity 3800 4158 +358
============================================
Files 707 709 +2
Lines 24280 24296 +16
Branches 4061 4064 +3
============================================
Hits 19289 19289
- Misses 2795 2810 +15
- Partials 2196 2197 +1
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.
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-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java`:
- Around line 18-22: Add Javadoc to the public getHostName() method in
oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java
(lines 18-22), and to getNetworkParams() in
oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.java
(line 60),
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
(lines 29-32), and
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
(lines 24-27), following the project’s existing Javadoc conventions.
🪄 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 Plus
Run ID: 3650c0d1-e3b0-44cd-8145-cef9f1d8d51e
📒 Files selected for processing (8)
CHANGELOG.mdoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*.java: Do not useorg.slf4j.event.**; useoshi.util.LogLevelinstead.
Add the imports needed by code, and let Spotless own formatting and import ordering.
Verify native struct offsets, field widths, andsysctl/ioctlconstants against the target operating system's real headers rather than inferring them from another OS.
Files:
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java
oshi-core-ffm/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-core-ffm/src/main/java/**/*.java:oshi-core-ffmmust not referencecom.sun.jna.**.
Behavior changes in FFM implementation classes should also be applied equivalently to their corresponding JNA twins, unless the difference is intentionally specific to FFM or JNA.
Files:
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
**/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/src/main/java/**/*.java: Every public member must have Javadoc, and code and Javadoc—including{@link...}—must use imported simple class names rather than fully qualified names.
New classes should declare an appropriate concurrency annotation fromoshi.annotation.concurrent, matching the modeled class when applicable.
Memoize constant or expensive, slowly changing system-call results withoshi.util.Memoizer, following surrounding patterns and usingdefaultExpiration()when values must refresh.
Place reusable per-OS acquisition and parsing helpers inoshi/driver/<os>/; keep parsing logic out of HAL classes where practical.
Prefer native calls for system information; on Linux preferFileUtilfor/procand/sys, while on other platformsExecutingCommandis acceptable when native APIs do not expose the information.
Do not commit generated output,target/, or IDE files.
Files:
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java
oshi-core/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-core/src/main/java/**/*.java:oshi-coremust compile with Java 8; do not use modern features such asvar, records, switch expressions, text blocks,List.of, orStream.toList().
Behavior changes in JNA implementation classes should also be applied equivalently to their corresponding FFM twins, unless the difference is intentionally specific to JNA or FFM.
Files:
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
oshi-common/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-common/src/main/java/**/*.java: Keeposhi-commonpure Java 8 with no JNA, FFM, or native library loading references; shared parsing, conversion, filtering, caching, and validation logic belongs here rather than duplicated in implementation modules.
Useoshi.util.ParseUtilmethods instead of banned numeric parsing APIs such asInteger.parseInt,Long.parseLong,Double.parseDouble, andInteger.decode.
Files:
oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java
🧠 Learnings (5)
📚 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-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java
📚 Learning: 2026-08-02T23:56:23.866Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3565
File: oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java:51-56
Timestamp: 2026-08-02T23:56:23.866Z
Learning: For Java FFM bindings in the oshi-core-ffm module, assume a 64-bit JVM and 64-bit operating system. Do not flag 32-bit native ABI or memory-layout compatibility concerns, consistent with the project's JDK 25 support policy, unless that policy changes.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.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/unix/openbsd/OpenBsdNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
📚 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/unix/openbsd/OpenBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java
🔇 Additional comments (7)
oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java (1)
12-16: LGTM!Also applies to: 34-40
CHANGELOG.md (1)
8-8: LGTM!oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.java (1)
40-41: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsFFM.java (1)
1-39: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java (1)
19-19: LGTM!oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdNetworkParamsJNA.java (1)
1-32: LGTM!oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java (1)
14-14: LGTM!
OpenBSD had no
getHostName()override, so it fell through toAbstractNetworkParams, which callsInetAddress.getLocalHost(). That resolves the name rather than just reading it, so on a host whose hostname is not resolvable — routine in a container, or with no/etc/hostsentry — it throwsUnknownHostException, degrades togetLoopbackAddress(), and reportslocalhostinstead of the real name. It can also block on a DNS timeout.gethostname(2)is a plain syscall with neither failure mode.Every other platform already prefers the native call and keeps the JDK lookup as its fallback:
gethostnameInetAddressShape
Follows the FreeBSD pattern exactly:
OpenBsdNetworkParamsbecomes abstract with aqueryHostName()hook and the prefer-native-fall-back-to-super override; thin JNA and FFM subclasses supply the binding.getNetworkParams()moves from the shared OS base to the two backend subclasses, which is what lets them differ.The FFM half only became possible with #3565 — OpenBSD never bound
gethostnameitself and now inherits it fromPosixLibcFunctions.What is deliberately not done
NetBSD stays on the JDK path. Its OS class is concrete with no FFM subclass, and there is no
NetBsdLibcFunctionsat all, because pkgsrc has no JDK 25 and its FFM backend takes the no-native route on purpose. Giving it a native host name would mean building that whole layer for one function. The JDK path cannot break when JDK 25 does arrive. Tracked on #3348.DragonFly needs nothing — it returns
FreeBsdNetworkParams{JNA,FFM}and already has the native call.On verification
OpenBSD is the best-covered of the three platforms for this change: CI runs it on JDK 25 with aggregate coverage, so both backends exercise the new path on the next run. That is a stronger position than DragonFly, whose FFM code is untested on-platform because its runner is JDK 21 — and which already ships this same native call.
Full gate green from clean: install, spotless, checkstyle, forbiddenapis, javadoc, 1509 tests / 0 failed.
Summary by CodeRabbit
New Features
Documentation