Repository navigation
Fix three JNA/FFM twin divergences on the file-system and network paths - #3569
Conversation
Found by a normalized set-difference sweep over the JNA/FFM twin pairs, which surfaces divergences that duplication detection structurally cannot (the differing lines are exactly what a duplicate-block matcher discards). - MacFileSystemFFM: the DiskArbitration session guard tested the returned foreign pointer for Java null. DASessionCreate is an ADDRESS downcall, so it yields MemorySegment.NULL on failure and never Java null; the guard was dead and the "unable to open session" bail never fired. Use isNull(), matching the sibling MacHWDiskStoreFFM. - WindowsFileSystem: a volume whose mount-point list overflows the buffer was dropped. The JNA twin had no retry at all; the FFM twin retried but keyed on 0x7A (ERROR_INSUFFICIENT_BUFFER) whereas GetVolumePathNamesForVolumeName reports a short buffer with ERROR_MORE_DATA (234), so its retry never fired either. JNA now retries with a right-sized buffer on ERROR_MORE_DATA, and FFM uses the correct named constant. - IPHlpAPIUtilFFM: the TCP/UDP connection queries sized once then fetched once, throwing Win32Exception on ERROR_INSUFFICIENT_BUFFER. Under connection churn the table can grow between the two calls, transiently reporting no connections for a family. Retry on ERROR_INSUFFICIENT_BUFFER with the newly reported size, matching the JNA do/while loop.
|
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)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
🧰 Additional context used📓 Path-based instructions (3)oshi-core/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (4)📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-07-30T00:35:22.638ZApplied to files:
📚 Learning: 2026-08-03T00:46:14.953ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughThe changes update macOS Disk Arbitration session validation and Windows volume and connection-table buffer handling. Windows FFM and JNA networking paths now use bounded retries. Windows volume paths retry with reported buffer sizes. ChangesPlatform error handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
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-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.java`:
- Around line 209-215: Bound the ERROR_INSUFFICIENT_BUFFER retry loops in the
TCP and UDP GetExtended*Table query blocks, including the paths around the
visible TCP loop and corresponding UDP flows. Limit retries to a small fixed
maximum, then exit through the existing default/failure return behavior when the
limit is exhausted, while preserving allocation and retry behavior for attempts
within the bound.
🪄 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: cac25259-cf0b-4c15-8ad4-04ed59c14513
📒 Files selected for processing (5)
CHANGELOG.mdoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout. (5)
- GitHub Check: Analyze (java)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.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/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.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/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.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/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.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/windows/WindowsFileSystemJNA.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/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.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/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.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/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.java
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.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/WindowsFileSystemJNA.java
🔇 Additional comments (4)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java (1)
88-88: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java (1)
33-33: LGTM!Also applies to: 182-185
oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java (1)
17-17: LGTM!Also applies to: 154-181
CHANGELOG.md (1)
10-10: LGTM!
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3569 +/- ##
============================================
- Coverage 79.57% 79.45% -0.12%
Complexity 3814 3814
============================================
Files 709 709
Lines 24223 24248 +25
Branches 4046 4052 +6
============================================
- Hits 19276 19267 -9
- Misses 2766 2790 +24
- Partials 2181 2191 +10
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:
|
The ERROR_INSUFFICIENT_BUFFER retry added for the Windows FFM TCP/UDP connection queries was unbounded. The table only reallocates when it has genuinely outgrown the just-measured size, so it is not a spin, but a table under sustained churn could reallocate from the confined arena repeatedly without freeing the prior buffer. Cap it at 5 retries; when exhausted, ret stays ERROR_INSUFFICIENT_BUFFER and the existing failure path returns the empty list. Apply the same bound to the JNA twin's four do/while loops so the two implementations stay consistent (the divergence class this PR exists to close). Both sides now allow one fetch plus at most five retries.
The monotonic() clamps added in #3574 are read-modify-writes on volatile long fields, which Sonar flags as S3078. The read-modify-write is one of ~20 unsynchronized volatile writes in updateAttributes(); OSProcess documents that concurrent callers must synchronize externally, and both racing writers only ever raise the value, so a lost clamp still yields a real ps reading. Suppress on the two methods rather than convert the shared protected fields to AtomicLong. Also restore ascending PR-number order in the 7.4.4 changelog, where the #3574 squash-merge landed the entry above #3569 and #3573.
…3582) * Retry the AIX perfstat_process fill when the buffer filled exactly perfstat_process is a count-then-fill pair, and it returns its array sorted by pid, so a buffer sized from the first call loses the highest-pid entries when processes spawn in between. The entry lost is most often the calling JVM's own, which is the newest process in the list. Both twins padded the allocation by 10 to absorb that churn, which is a guess rather than a guarantee. Observed on the shared cfarm AIX host: five NativeComparisonTest cases failed together on both attempts of one run, all of them rooted in getProcess(getProcessId()) returning null, and the same commit passed on a re-run minutes later. Under a busy box more than 10 processes appeared between the two calls. Treat a return equal to the allocation as possible truncation: re-count and retry, bounded at 3 attempts, after which the result is returned as is because a short list still beats none. Also raise the pad from 10 to 64, which costs a few KB of a confined arena and makes the retry a rare path rather than the common one. Applied to both backends. This is the count-then-fetch race class that #3569 fixed for the Windows connection tables, in a different API. Not reproducible off AIX, and load-dependent even there, so CI passing does not confirm the fix; it confirms no regression. The reasoning rests on the perfstat contract and the sorted-by-pid ordering the previous comment already documented. * Keep the full buffer when the perfstat re-count fails The truncation retry re-counted the processes to size the next attempt, and assigned that straight back to the loop variable. A re-count that returns zero or an error then failed the loop guard, so the method fell out and returned an empty array -- discarding the full buffer of entries it had just read successfully. That is worse than the behavior this PR set out to fix: a list that may be missing its tail became no list at all, on a path reachable whenever perfstat transiently fails between two calls. Hold the re-count in a local and only retry when it is positive. Otherwise fall through and map the buffer already in hand, which is the same result the code produced before the retry existed. Both twins. * Scale the perfstat pad with the process count, with a floor The slack absorbs processes spawned between the count and fill calls, so what it needs to track is the system's spawn rate, not its process count. Those correlate weakly, and the two cases pull opposite ways. A small, busy host churns faster than any proportional pad would cover: at 200 processes a 10% pad is 20 entries, fewer than the fixed 64, and this is the shape of host that produced the original failure. A large host makes that same fixed 64 thin — 1.3% headroom at 5000 processes — where a proportional term is the one that helps. So take whichever is larger: count/10 or 64. Extracted as paddedSize() in both twins with the reasoning recorded, since neither half is redundant. Cost is immaterial either way. perfstat_process_t is 288 bytes, so the proportional term adds 144 KB at 5000 processes, and the retry loop is what provides correctness — the pad only decides how often that retry has to run.
Found by a normalized set-difference sweep over the JNA/FFM twin pairs — stripping the
JNA/FFMsuffixes, reducing each side to its logic lines, andcomm-ing the two. This surfaces divergences that duplication detection structurally cannot: a duplicate-block matcher discards exactly the differing lines, which is where these bugs live. All three are edge-case guards present on one twin and missing (or misconfigured) on the other; none is reachable on the happy path, which is why they survived.1. macOS FFM file store — dead DiskArbitration null guard
MacFileSystemFFMguarded the DiskArbitration session withsession.segment() == null.DASessionCreateis anADDRESSdowncall, so on failure it returnsMemorySegment.NULL, never Javanull— the guard was dead and the "Unable to open session" bail never fired. This was the onlysegment() == nullin the whole FFM module; the siblingMacHWDiskStoreFFMalready usesisNull(). The JNA twin bails correctly. Fixed tosession.isNull().2. Windows file system — mount-point list buffer overflow
A volume whose mount-point list exceeds the buffer was dropped from the results:
WindowsFileSystemJNA) had no retry at all and passednullfor the return-length pointer. Now retries once with a right-sized buffer onERROR_MORE_DATA.WindowsFileSystemFFM) had a retry, but keyed it on0x7A(ERROR_INSUFFICIENT_BUFFER), whereasGetVolumePathNamesForVolumeNamereports a short buffer withERROR_MORE_DATA(234) — so its retry never fired either. Now uses the correct named constant.3. Windows FFM TCP/UDP connections — no size-race retry
IPHlpAPIUtilFFM's four connection queries sized once then fetched once, throwingWin32ExceptiononERROR_INSUFFICIENT_BUFFER. Under connection churn the table can grow between the two calls, transiently reporting no connections for that family. The JNA twin loops onERROR_INSUFFICIENT_BUFFER; the FFM queries now do the same.Verification
Built and tested on macOS (JDK 25+ toolchain, so the FFM module is compiled):
spotless:apply,checkstyle:check,install(tests green), andforbiddenapis:checkall pass onoshi-core/oshi-core-ffm. The Windows paths compile but are not executable from this host; CI covers Windows. Thejavadoc:javadocaggregator step fails identically on cleanmaster(a named/unnamed-module reactor-composition issue, unrelated to these changes, which add only line comments).Summary by CodeRabbit