Repository navigation
Expand JNA vs FFM comparison tests for InternetProtocolStats - #3209
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplaces loose protocol-stat checks with cumulative counter comparisons (FFM ≥ JNA for TCP/UDP v4/v6), adds a new connection-list comparison test, and refactors MacInternetProtocolStatsFFM.getConnections() to use a single PID buffer and a per-PID Arena passed into helper queries with added logging and retry behavior. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as NativeComparisonTest
participant JNA as JNA impl
participant FFM as MacInternetProtocolStatsFFM
participant Kernel as macOS proc APIs
Test->>JNA: fetch internet protocol stats & connections
JNA-->>Test: return stats, connection list
Test->>FFM: fetch internet protocol stats & connections
FFM->>Kernel: proc_listpids (single PID buffer)
Kernel-->>FFM: PID bytes
FFM->>FFM: create per-PID Arena (shared for PID)
loop per PID
FFM->>Kernel: proc_pidinfo / proc_pidfdinfo (may retry with larger buffer)
Kernel-->>FFM: fd/socket info
FFM-->>FFM: parse IPConnection entries (apply validation, counters, logging)
end
FFM-->>Test: return stats, connection list
Test->>Test: compare stats (FFM ≥ JNA) and connection lists (null/empty agreement, size ratio, tuple overlap, per-entry validation)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
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 #3209 +/- ##
==========================================
+ Coverage 59.55% 60.42% +0.87%
==========================================
Files 423 423
Lines 20369 20367 -2
Branches 3575 3572 -3
==========================================
+ Hits 12130 12307 +177
+ Misses 6476 6280 -196
- Partials 1763 1780 +17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
460-472: Consider unique-key overlap to avoid duplicate inflation.The current overlap count increments per FFM row. If duplicate tuples exist, overlap can be overstated. Using unique tuple sets on both sides makes this signal stricter.
Refactor option
- int overlap = 0; - for (InternetProtocolStats.IPConnection c : ffmConns) { - if (jnaKeys.contains(c.getType() + ":" + c.getLocalPort() + ":" + c.getForeignPort())) { - overlap++; - } - } - // At least 50% of FFM connections should match JNA (ephemeral ports may differ) - assertThat(overlap).as("connection overlap").isGreaterThanOrEqualTo(ffmConns.size() / 2); + java.util.Set<String> ffmKeys = new java.util.HashSet<>(); + for (InternetProtocolStats.IPConnection c : ffmConns) { + ffmKeys.add(c.getType() + ":" + c.getLocalPort() + ":" + c.getForeignPort()); + } + long overlap = ffmKeys.stream().filter(jnaKeys::contains).count(); + // At least 50% of unique FFM connection keys should match JNA + assertThat(overlap).as("connection overlap").isGreaterThanOrEqualTo(ffmKeys.size() / 2L);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 460 - 472, The overlap count currently increments per ffmConns row and can be inflated by duplicate tuples; instead build a Set<String> ffmKeys of the same tuple form used in jnaKeys (e.g., c.getType()+":"+c.getLocalPort()+":"+c.getForeignPort()), then compute the intersection size via retaining/intersecting the two sets (or iterating ffmKeys and counting membership in jnaKeys) to get a unique overlap count, and update the assertion to compare that uniqueOverlap against ffmKeys.size()/2 (or desired threshold); update references in the test where jnaKeys, ffmConns and overlap are used (replace the overlap loop and assertion with the set-based logic).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 455-458: The test currently asserts ffmConns is non-empty but only
checks jnaConns for non-null before calling assertWithinRatio; update
NativeComparisonTest to add an explicit non-empty assertion for jnaConns (e.g.,
assertThat(jnaConns).as("JNA should have connections").isNotEmpty()) immediately
before the assertWithinRatio call so the ratio check has a valid baseline and
uses the existing ffmConns, jnaConns, and assertWithinRatio symbols.
- Around line 423-443: Add missing IPv6 "received" assertions in
NativeComparisonTest: after retrieving jnaTcp6 and ffmTcp6 (getTCPv6Stats) add
an assertion that ffmTcp6.getSegmentsReceived() is
greaterThanOrEqualTo(jnaTcp6.getSegmentsReceived()); similarly, after retrieving
jnaUdp6 and ffmUdp6 (getUDPv6Stats) add an assertion that
ffmUdp6.getDatagramsReceived() is
greaterThanOrEqualTo(jnaUdp6.getDatagramsReceived()); use the existing
assertThat pattern and descriptive as(...) messages to mirror the other checks
(variables ffmTcp6, jnaTcp6, ffmUdp6, jnaUdp6 in NativeComparisonTest).
---
Nitpick comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 460-472: The overlap count currently increments per ffmConns row
and can be inflated by duplicate tuples; instead build a Set<String> ffmKeys of
the same tuple form used in jnaKeys (e.g.,
c.getType()+":"+c.getLocalPort()+":"+c.getForeignPort()), then compute the
intersection size via retaining/intersecting the two sets (or iterating ffmKeys
and counting membership in jnaKeys) to get a unique overlap count, and update
the assertion to compare that uniqueOverlap against ffmKeys.size()/2 (or desired
threshold); update references in the test where jnaKeys, ffmConns and overlap
are used (replace the overlap loop and assertion with the set-based logic).
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4bb8552c-423f-40d6-9783-a215a08aa22d
📒 Files selected for processing (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 11, ubuntu-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
| // Both should return connections; counts may differ slightly due to timing | ||
| assertThat(ffmConns).as("FFM should have connections").isNotEmpty(); | ||
| assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.25, "connections.size"); | ||
|
|
There was a problem hiding this comment.
Assert JNA connection list is non-empty before ratio checks.
Line 456 enforces non-empty FFM results, but JNA is only checked for non-null. Add a non-empty assertion for JNA too so the test contract is explicit and the ratio check has a meaningful baseline.
Proposed patch
// Both should return connections; counts may differ slightly due to timing
assertThat(ffmConns).as("FFM should have connections").isNotEmpty();
+ assertThat(jnaConns).as("JNA should have connections").isNotEmpty();
assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.25, "connections.size");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`
around lines 455 - 458, The test currently asserts ffmConns is non-empty but
only checks jnaConns for non-null before calling assertWithinRatio; update
NativeComparisonTest to add an explicit non-empty assertion for jnaConns (e.g.,
assertThat(jnaConns).as("JNA should have connections").isNotEmpty()) immediately
before the assertWithinRatio call so the ratio check has a valid baseline and
uses the existing ffmConns, jnaConns, and assertWithinRatio symbols.
46dbdc1 to
58ea4da
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
461-463:⚠️ Potential issue | 🟠 MajorGuard against one-sided empties before returning.
Line 461 currently returns when either list is empty, which can let a real JNA/FFM divergence pass silently. Assert empty/non-empty parity first, then return only when both are empty.
Based on learnings: in volatile comparison tests, the reliable contract is often “both empty or both non-empty,” not exact count matching.Proposed patch
- if (jnaConns.isEmpty() || ffmConns.isEmpty()) { - return; - } + if (jnaConns.isEmpty() || ffmConns.isEmpty()) { + assertThat(ffmConns.isEmpty()).as("JNA/FFM connection emptiness parity") + .isEqualTo(jnaConns.isEmpty()); + return; + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 461 - 463, The current early return in NativeComparisonTest (checking jnaConns.isEmpty() || ffmConns.isEmpty()) can hide one-sided empties; change it to first assert parity of emptiness between jnaConns and ffmConns (e.g., assertTrue(jnaConns.isEmpty() == ffmConns.isEmpty()) or equivalent) to fail the test when only one is empty, and only return early when both are empty; update the block that references jnaConns and ffmConns in the test method in NativeComparisonTest.java accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 480-481: The assertion currently checks intersection.size()
against ffmKeys.size() / 4 which yields a 25% threshold and can truncate to 0
for small sets; change the threshold to 50% and compute it with an explicit
ceiling so small ffmKeys still require at least one overlap (e.g., compute
threshold via Math.ceil(ffmKeys.size() * 0.5) or (ffmKeys.size() + 1) / 2) and
then assertThat(intersection.size()).as("unique connection tuple
overlap").isGreaterThanOrEqualTo(theComputedThreshold) using the existing
intersection and ffmKeys variables in NativeComparisonTest (the assertion block
shown).
---
Duplicate comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 461-463: The current early return in NativeComparisonTest
(checking jnaConns.isEmpty() || ffmConns.isEmpty()) can hide one-sided empties;
change it to first assert parity of emptiness between jnaConns and ffmConns
(e.g., assertTrue(jnaConns.isEmpty() == ffmConns.isEmpty()) or equivalent) to
fail the test when only one is empty, and only return early when both are empty;
update the block that references jnaConns and ffmConns in the test method in
NativeComparisonTest.java accordingly.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 04761167-1261-4747-9297-5cd0d085ed20
📒 Files selected for processing (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
| assertThat(intersection.size()).as("unique connection tuple overlap") | ||
| .isGreaterThanOrEqualTo(ffmKeys.size() / 4); |
There was a problem hiding this comment.
Overlap threshold is weaker than intended (25% with truncation).
Line 481 uses ffmKeys.size() / 4, which enforces only 25% overlap and may require 0 overlap for small sets due to integer division. If the target is 50% overlap, compute an explicit ceiling threshold.
Proposed patch
- assertThat(intersection.size()).as("unique connection tuple overlap")
- .isGreaterThanOrEqualTo(ffmKeys.size() / 4);
+ int minOverlap = (int) Math.ceil(ffmKeys.size() * 0.5);
+ assertThat(intersection.size()).as("unique connection tuple overlap")
+ .isGreaterThanOrEqualTo(minOverlap);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| assertThat(intersection.size()).as("unique connection tuple overlap") | |
| .isGreaterThanOrEqualTo(ffmKeys.size() / 4); | |
| int minOverlap = (int) Math.ceil(ffmKeys.size() * 0.5); | |
| assertThat(intersection.size()).as("unique connection tuple overlap") | |
| .isGreaterThanOrEqualTo(minOverlap); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`
around lines 480 - 481, The assertion currently checks intersection.size()
against ffmKeys.size() / 4 which yields a 25% threshold and can truncate to 0
for small sets; change the threshold to 50% and compute it with an explicit
ceiling so small ffmKeys still require at least one overlap (e.g., compute
threshold via Math.ceil(ffmKeys.size() * 0.5) or (ffmKeys.size() + 1) / 2) and
then assertThat(intersection.size()).as("unique connection tuple
overlap").isGreaterThanOrEqualTo(theComputedThreshold) using the existing
intersection and ffmKeys variables in NativeComparisonTest (the assertion block
shown).
58ea4da to
0745196
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
469-478: Consider importingSetandHashSetfor consistency.The rest of the file uses imported
java.util.*types (List, Map, etc.), but these lines use fully qualified names. A minor style nit — works fine either way.♻️ Optional import cleanup
Add to imports:
import java.util.HashSet; import java.util.Set;Then simplify:
- java.util.Set<String> jnaKeys = new java.util.HashSet<>(); + Set<String> jnaKeys = new HashSet<>(); for (InternetProtocolStats.IPConnection c : jnaConns) { jnaKeys.add(c.getType() + ":" + c.getLocalPort() + ":" + c.getForeignPort()); } - java.util.Set<String> ffmKeys = new java.util.HashSet<>(); + Set<String> ffmKeys = new HashSet<>(); for (InternetProtocolStats.IPConnection c : ffmConns) { ffmKeys.add(c.getType() + ":" + c.getLocalPort() + ":" + c.getForeignPort()); } // Count unique tuples present in both - java.util.Set<String> intersection = new java.util.HashSet<>(ffmKeys); + Set<String> intersection = new HashSet<>(ffmKeys);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 469 - 478, Replace the fully qualified java.util types used in the NativeComparisonTest methods with imports: add imports for java.util.Set and java.util.HashSet and then change declarations of jnaKeys, ffmKeys and intersection from "java.util.Set<String>" and "new java.util.HashSet<>()" to use Set<String> and new HashSet<>() respectively (affecting variables jnaKeys, ffmKeys and intersection) to match the rest of the file's style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 469-478: Replace the fully qualified java.util types used in the
NativeComparisonTest methods with imports: add imports for java.util.Set and
java.util.HashSet and then change declarations of jnaKeys, ffmKeys and
intersection from "java.util.Set<String>" and "new java.util.HashSet<>()" to use
Set<String> and new HashSet<>() respectively (affecting variables jnaKeys,
ffmKeys and intersection) to match the rest of the file's style.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 85211a34-7cc3-4350-90cf-dfbb5b6556c7
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
🔇 Additional comments (4)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (2)
144-169: LGTM! Nice Arena lifecycle consolidation.Reusing a single
Arenaacross allqueryFdListandqueryIPConnectioncalls is a solid performance improvement — it avoids repeated allocation/deallocation overhead for each PID and FD iteration. The try-with-resources at line 144 ensures proper cleanup.
172-194: Clean parameter threading for shared Arena.The helper methods now receive the
Arenaas a parameter rather than managing their own lifecycle. This is a sensible pattern — the caller (getConnections) owns the resource, and helpers simply allocate within it. Exception handling still returns gracefully with empty results.oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (2)
412-447: Comprehensive cumulative counter assertions.Good coverage of all TCP/UDP v4/v6 stats with the appropriate monotonic assertion pattern (FFM called second, so counters should be ≥ JNA). The inclusion of both sent and received counters for IPv6 addresses prior feedback.
483-489: Solid structural validation matching existing test patterns.The checks for non-empty type, valid port range (0–65535), and non-null state align well with the established contract in
InternetProtocolStatsTest.testGetConnections(). Good consistency.
988983e to
5685b26
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
482-483:⚠️ Potential issue | 🟠 MajorRaise overlap floor to 50% and avoid integer truncation to zero.
Line 483 enforces only 25% overlap (
/ 4) and can require zero overlap for small sets due to integer truncation.Suggested patch
- assertThat(intersection.size()).as("unique connection tuple overlap") - .isGreaterThanOrEqualTo(ffmKeys.size() / 4); + int minOverlap = (int) Math.ceil(ffmKeys.size() * 0.5); + assertThat(intersection.size()).as("unique connection tuple overlap") + .isGreaterThanOrEqualTo(minOverlap);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 482 - 483, The assertion currently checks intersection.size() against ffmKeys.size() / 4 which enforces only 25% overlap and can truncate to zero for small ffmKeys; update the check to require at least 50% overlap and avoid truncation by computing a rounded-up half of ffmKeys (e.g., use a rounded-up expression based on ffmKeys.size()) so the call to assertThat(intersection.size())....isGreaterThanOrEqualTo(...) uses that rounded-up 50% threshold rather than ffmKeys.size() / 4.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 467-468: The test currently allows a 50% tolerance for
connection-count parity; update the assertion in NativeComparisonTest so it
enforces the intended 25% tolerance by changing the ratio passed to
assertWithinRatio from 0.50 to 0.25 when comparing ffmConns.size() and
jnaConns.size() (the call referencing assertWithinRatio(ffmConns.size(),
jnaConns.size(), ... , "connections.size")).
---
Duplicate comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 482-483: The assertion currently checks intersection.size()
against ffmKeys.size() / 4 which enforces only 25% overlap and can truncate to
zero for small ffmKeys; update the check to require at least 50% overlap and
avoid truncation by computing a rounded-up half of ffmKeys (e.g., use a
rounded-up expression based on ffmKeys.size()) so the call to
assertThat(intersection.size())....isGreaterThanOrEqualTo(...) uses that
rounded-up 50% threshold rather than ffmKeys.size() / 4.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0325453d-5d71-4bc9-9d26-9769675c0b11
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
🔇 Additional comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
415-448: Nice strengthening of cumulative TCP/UDP assertions.This expands coverage in the right direction (v4/v6 + sent/received) while keeping monotonic
FFM >= JNAsemantics for cumulative counters.
| // Connection counts can fluctuate significantly between the two reads | ||
| assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size"); |
There was a problem hiding this comment.
Use the intended 25% size tolerance for connection-count parity.
Line 468 currently allows a 50% delta (0.50), which is looser than the PR objective and can hide larger backend divergence.
Suggested patch
- assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size");
+ assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.25, "connections.size");📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Connection counts can fluctuate significantly between the two reads | |
| assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size"); | |
| // Connection counts can fluctuate significantly between the two reads | |
| assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.25, "connections.size"); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`
around lines 467 - 468, The test currently allows a 50% tolerance for
connection-count parity; update the assertion in NativeComparisonTest so it
enforces the intended 25% tolerance by changing the ratio passed to
assertWithinRatio from 0.50 to 0.25 when comparing ffmConns.size() and
jnaConns.size() (the call referencing assertWithinRatio(ffmConns.size(),
jnaConns.size(), ... , "connections.size")).
5685b26 to
81290ee
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
461-477:⚠️ Potential issue | 🟠 MajorConnection parity thresholds are still looser than intended.
Line 462 keeps a
0.50size tolerance, and Line 477 enforces only ~25% overlap with truncation. This under-tests backend parity versus the target criteria.Suggested patch
- assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size"); + assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.25, "connections.size"); @@ - assertThat(intersection.size()).as("unique connection tuple overlap") - .isGreaterThanOrEqualTo(ffmKeys.size() / 4); + int minOverlap = (ffmKeys.size() + 1) / 2; // ceil(50%) + assertThat(intersection.size()).as("unique connection tuple overlap") + .isGreaterThanOrEqualTo(minOverlap);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 461 - 477, Tighten the connection-parity checks: reduce the size-tolerance in the assertWithinRatio call from 0.50 to 0.20 (so the size comparison between ffmConns and jnaConns is stricter) and strengthen the overlap assertion to require at least 75% of unique tuples match instead of ~25% — compute the threshold as a proper 75% of ffmKeys (e.g., use ffmKeys.size() * 0.75 and round/ceil to an int) and assert intersection.size() >= that value; update checks around assertWithinRatio, jnaKeys/ffmKeys construction, and the intersection.size() assertion accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 461-477: Tighten the connection-parity checks: reduce the
size-tolerance in the assertWithinRatio call from 0.50 to 0.20 (so the size
comparison between ffmConns and jnaConns is stricter) and strengthen the overlap
assertion to require at least 75% of unique tuples match instead of ~25% —
compute the threshold as a proper 75% of ffmKeys (e.g., use ffmKeys.size() *
0.75 and round/ceil to an int) and assert intersection.size() >= that value;
update checks around assertWithinRatio, jnaKeys/ffmKeys construction, and the
intersection.size() assertion accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4ebb99c5-4986-4d11-b881-2393c3831bd2
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
🔇 Additional comments (2)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
158-165: Per-PID Arena refactor looks solid.Nice change: passing a PID-scoped
ArenaintoqueryFdListandqueryIPConnectionkeeps allocation lifetimes explicit and consistent across the connection walk.Also applies to: 174-176, 198-199
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
415-442: Good strengthening of protocol counter coverage.Comparing both sent and received fields for TCP/UDP v4/v6 materially improves parity checks without over-constraining timing-sensitive counters.
134a5b6 to
b429156
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
64-75:⚠️ Potential issue | 🟠 MajorRestore the memoizer setting after this class.
GlobalConfigis JVM-wide. LeavingOSHI_UTIL_MEMOIZER_EXPIRATIONat0after@BeforeAllcan change the behavior of later comparison tests and make failures order-dependent. Please save the previous value here and restore it in an@AfterAll.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 64 - 75, The test disables the JVM-wide memoizer GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION in setup() but does not restore it, causing test-order coupling; capture the previous value into a static field (e.g., previousMemoizerExpiration) before setting it to 0 in setup(), and add an `@AfterAll` method (e.g., teardown() or restoreMemoizer()) that resets GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION back to the saved previous value to ensure other tests are unaffected.
♻️ Duplicate comments (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (2)
471-472:⚠️ Potential issue | 🟠 MajorTighten the connection-count tolerance to the stated 25%.
This still allows a 50% delta, which is looser than the PR contract and can hide larger JNA/FFM drift.
Suggested fix
- assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size"); + assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.25, "connections.size");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 471 - 472, The tolerance for connection-count comparison is too loose: change the call to assertWithinRatio that compares ffmConns.size() and jnaConns.size() from 0.50 to 0.25 (keep the same "connections.size" message) so the test enforces the intended 25% delta in NativeComparisonTest.
483-487:⚠️ Potential issue | 🟠 MajorThe overlap check is still enforcing 25%, not 50%.
ffmKeys.size() / 4only requires one-quarter overlap, and integer truncation can reduce the minimum to0for small sets. If the intended bar is 50%, compute that threshold explicitly.Suggested fix
// Count unique tuples present in both Set<String> intersection = new HashSet<>(ffmKeys); intersection.retainAll(jnaKeys); + int minOverlap = (ffmKeys.size() + 1) / 2; assertThat(intersection.size()).as("unique connection tuple overlap") - .isGreaterThanOrEqualTo(ffmKeys.size() / 4); + .isGreaterThanOrEqualTo(minOverlap);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 483 - 487, The test currently asserts a 25% overlap using "ffmKeys.size() / 4" which also suffers integer-truncation for small sets; change the threshold to 50% by computing an explicit half using ceiling to avoid truncation (e.g., int expected = (int) Math.ceil(ffmKeys.size() * 0.5)); then replace the assertion parameter in the intersection size check (the assertThat(...).isGreaterThanOrEqualTo(...) call referencing intersection, ffmKeys, jnaKeys) with that expected value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`:
- Around line 148-155: The loop can read past pidBuffer because numProcs = bytes
/ Integer.BYTES may exceed the actual buffer capacity due to the extra slot;
clamp numProcs to the buffer's capacity before iterating. Change the logic
around proc_listpids/numProcs to compute an upper bound like Math.min(numProcs,
pidBuffer.capacity() / Integer.BYTES or bufferSize / Integer.BYTES) and use that
clamped value in the for loop that reads from pidBuffer (references:
proc_listpids, pidBuffer, numProcs, bufferSize, Integer.BYTES).
---
Outside diff comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 64-75: The test disables the JVM-wide memoizer
GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION in setup() but does not restore it,
causing test-order coupling; capture the previous value into a static field
(e.g., previousMemoizerExpiration) before setting it to 0 in setup(), and add an
`@AfterAll` method (e.g., teardown() or restoreMemoizer()) that resets
GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION back to the saved previous value to
ensure other tests are unaffected.
---
Duplicate comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 471-472: The tolerance for connection-count comparison is too
loose: change the call to assertWithinRatio that compares ffmConns.size() and
jnaConns.size() from 0.50 to 0.25 (keep the same "connections.size" message) so
the test enforces the intended 25% delta in NativeComparisonTest.
- Around line 483-487: The test currently asserts a 25% overlap using
"ffmKeys.size() / 4" which also suffers integer-truncation for small sets;
change the threshold to 50% by computing an explicit half using ceiling to avoid
truncation (e.g., int expected = (int) Math.ceil(ffmKeys.size() * 0.5)); then
replace the assertion parameter in the intersection size check (the
assertThat(...).isGreaterThanOrEqualTo(...) call referencing intersection,
ffmKeys, jnaKeys) with that expected value.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6256fe76-ec08-4373-8d11-8a0c71291965
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- 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: Test JDK 11, macos-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-03T18:44:48.200Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:48.200Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
b429156 to
194736c
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
151-160:⚠️ Potential issue | 🟠 MajorClamp
numProcstopidBuffercapacity before iteratingOn Line 154,
numProcsis derived directly from returned bytes; ifproc_listpidsreports more entries than fit (your Line 158 comment already hints this), the loop can read pastpidBufferand silently degrade into partial results through the outer catch.Suggested fix
- int numProcs = bytes / Integer.BYTES; + int maxProcs = bufferSize / Integer.BYTES; + int numProcs = Math.min(Math.max(bytes, 0) / Integer.BYTES, maxProcs);#!/bin/bash set -euo pipefail # Verify current handling in this file rg -n -C3 'proc_listpids\(|numProcs|bufferSize|pidBuffer.get' \ oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java # Compare with existing dynamic sizing pattern used elsewhere in repo rg -n -C4 'proc_listpids\(' \ oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java` around lines 151 - 160, Clamp the computed numProcs to the pidBuffer capacity before iterating: after calling proc_listpids and computing int numProcs = bytes / Integer.BYTES, compute the buffer capacity as int maxProcs = bufferSize / Integer.BYTES (or derive from pidBuffer if available) and set numProcs = Math.min(numProcs, maxProcs) so the subsequent loop and pidBuffer.get(JAVA_INT, (long) i * Integer.BYTES) cannot read past pidBuffer; keep existing off-by-one handling comment but ensure the loop bound uses the clamped numProcs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`:
- Around line 151-160: Clamp the computed numProcs to the pidBuffer capacity
before iterating: after calling proc_listpids and computing int numProcs = bytes
/ Integer.BYTES, compute the buffer capacity as int maxProcs = bufferSize /
Integer.BYTES (or derive from pidBuffer if available) and set numProcs =
Math.min(numProcs, maxProcs) so the subsequent loop and pidBuffer.get(JAVA_INT,
(long) i * Integer.BYTES) cannot read past pidBuffer; keep existing off-by-one
handling comment but ensure the loop bound uses the clamped numProcs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f0081fb0-bb92-44bd-ab84-ca959f231075
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
🚧 Files skipped from review as they are similar to previous changes (1)
- oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- 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: Test JDK 11, windows-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
🔇 Additional comments (1)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
162-166: Nice arena-lifetime cleanup per PIDGood change passing
pidArenaintoqueryFdListandqueryIPConnection; this avoids per-FD arena churn while keeping allocations scoped and deterministic.
be43735 to
d2fdf2e
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
151-155:⚠️ Potential issue | 🟠 MajorClamp
numProcsto the PID buffer capacity before iterating.
numProcs = bytes / Integer.BYTEScan exceed the allocated PID buffer, which can trigger an out-of-bounds read and silently degrade to partial results via the outer catch.Suggested fix
int bytes = proc_listpids(PROC_ALL_PIDS, 0, pidBuffer, bufferSize); - int numProcs = bytes / Integer.BYTES; + int numProcs = Math.min(Math.max(bytes, 0) / Integer.BYTES, bufferSize / Integer.BYTES); LOG.warn("[CONNDBG] proc_listpids returned {} bytes, {} procs", bytes, numProcs);#!/bin/bash # Verify whether loop bound is clamped to pidBuffer capacity rg -n -C2 'proc_listpids|numProcs|for \(int i = 0; i < numProcs' oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.javaAlso applies to: 160-164
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java` around lines 151 - 155, The computed numProcs from bytes / Integer.BYTES can exceed the PID buffer's capacity; before iterating over PIDs (the loop using numProcs after calling proc_listpids), clamp numProcs to the maximum entries the allocated pidBuffer can hold (bufferSize / Integer.BYTES) so you never read past pidBuffer; update the logic around proc_listpids, bufferSize, pidBuffer and numProcs (and the subsequent for loop) to use Math.min(numProcs, bufferSize / Integer.BYTES) (or equivalent) and apply the same clamp in the second occurrence at lines ~160-164.
🧹 Nitpick comments (1)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
155-155: Use DEBUG for[CONNDBG]diagnostics and pass exceptions directly to preserve stack trace.Lines 155 and 178 log success-path results; using WARN generates unnecessary noise in production. Line 181-182 should pass the exception directly rather than concatenating its string representation, which loses the stack trace and doesn't follow SLF4J best practices.
Suggested fix
- LOG.warn("[CONNDBG] proc_listpids returned {} bytes, {} procs", bytes, numProcs); + LOG.debug("[CONNDBG] proc_listpids returned {} bytes, {} procs", bytes, numProcs); ... - LOG.warn("[CONNDBG] returning {} connections, socketFds={}, ipcParsed={}", conns.size(), totalSocketFds, + LOG.debug("[CONNDBG] returning {} connections, socketFds={}, ipcParsed={}", conns.size(), totalSocketFds, totalIpc); ... - LOG.warn("[CONNDBG] caught exception in getConnections: {}", - e.getClass().getName() + ": " + e.getMessage()); + LOG.warn("getConnections failed", e);Also applies to: 178-182
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java` at line 155, Change the noisy WARN logs labeled "[CONNDBG]" in MacInternetProtocolStatsFFM to DEBUG (e.g., replace LOG.warn(...) with LOG.debug(...)) for the informational proc_listpids/proc_pidinfo messages, and for exception logging in the same class/methods (the places currently concatenating the exception string) switch to SLF4J's throwable-aware form—pass the exception as the last parameter to the logger (e.g., LOG.debug("message {}", var, throwable)) so the stack trace is preserved instead of being concatenated as text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`:
- Around line 151-155: The computed numProcs from bytes / Integer.BYTES can
exceed the PID buffer's capacity; before iterating over PIDs (the loop using
numProcs after calling proc_listpids), clamp numProcs to the maximum entries the
allocated pidBuffer can hold (bufferSize / Integer.BYTES) so you never read past
pidBuffer; update the logic around proc_listpids, bufferSize, pidBuffer and
numProcs (and the subsequent for loop) to use Math.min(numProcs, bufferSize /
Integer.BYTES) (or equivalent) and apply the same clamp in the second occurrence
at lines ~160-164.
---
Nitpick comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`:
- Line 155: Change the noisy WARN logs labeled "[CONNDBG]" in
MacInternetProtocolStatsFFM to DEBUG (e.g., replace LOG.warn(...) with
LOG.debug(...)) for the informational proc_listpids/proc_pidinfo messages, and
for exception logging in the same class/methods (the places currently
concatenating the exception string) switch to SLF4J's throwable-aware form—pass
the exception as the last parameter to the logger (e.g., LOG.debug("message {}",
var, throwable)) so the stack trace is preserved instead of being concatenated
as text.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2a006364-995a-408b-bfa8-2a03f59de33a
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
🚧 Files skipped from review as they are similar to previous changes (1)
- oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
🔇 Additional comments (1)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
165-170: Good refactor on arena ownership.Passing a per-PID arena into
queryFdList/queryIPConnectionimproves allocation lifetime control and keeps helper APIs explicit.Also applies to: 188-189, 212-213
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (4)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
151-164:⚠️ Potential issue | 🟠 MajorClamp PID iteration count to buffer capacity.
At Line 154,
numProcs = bytes / Integer.BYTEScan exceed the 1024-entry buffer size, which can make Line 163 read pastpidBufferand truncate results via the outer catch.Suggested fix
int bytes = proc_listpids(PROC_ALL_PIDS, 0, pidBuffer, bufferSize); - int numProcs = bytes / Integer.BYTES; + int numProcs = Math.min(Math.max(bytes, 0) / Integer.BYTES, bufferSize / Integer.BYTES); LOG.warn("[CONNDBG] proc_listpids returned {} bytes, {} procs", bytes, numProcs);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java` around lines 151 - 164, The loop can read past pidBuffer because numProcs is computed from bytes without considering the allocated buffer capacity; clamp numProcs to the buffer's entry capacity before iterating. Calculate the maximum entries as bufferSize / Integer.BYTES (or use the constant 1024), then set numProcs = Math.min(bytes / Integer.BYTES, maxEntries) (also treat negative/zero bytes defensively) before the for-loop that reads pidBuffer.get(...); this prevents out-of-bounds reads after calling proc_listpids.oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (3)
465-469:⚠️ Potential issue | 🟠 MajorAvoid early return on empty lists; require non-empty baseline.
Lines 466–468 allow the test to pass with both lists empty, skipping ratio/overlap/structure checks and reducing coverage of this path.
Suggested fix
- // Both sides should return connections or both should be empty - assertThat(ffmConns.isEmpty()).as("FFM and JNA should agree on emptiness").isEqualTo(jnaConns.isEmpty()); - if (jnaConns.isEmpty()) { - return; - } + assertThat(ffmConns).as("FFM connections").isNotEmpty(); + assertThat(jnaConns).as("JNA connections").isNotEmpty();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 465 - 469, The test currently returns early when both ffmConns and jnaConns are empty, skipping later validation; change the logic to assert a non-empty baseline instead of returning: after the equality check on emptiness, replace the early return with an assertion that jnaConns (or ffmConns) is not empty (e.g., use assertThat(jnaConns).as("Require non-empty baseline connections for comparison").isNotEmpty()), so the test fails when both are empty and continues to perform ratio/overlap/structure checks in NativeComparisonTest using ffmConns and jnaConns.
471-472:⚠️ Potential issue | 🟠 MajorUse the intended 25% size tolerance for connection counts.
Line 472 currently permits a 50% delta, which is looser than the stated target.
Suggested fix
- assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size"); + assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.25, "connections.size");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 471 - 472, The test currently uses a 50% tolerance for connection count comparison; change the tolerance passed to assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size") to 0.25 so the assertion enforces the intended 25% delta between ffmConns.size() and jnaConns.size() in NativeComparisonTest.java.
486-487:⚠️ Potential issue | 🟠 MajorRaise overlap threshold to 50% and avoid integer truncation.
ffmKeys.size() / 4enforces only 25%, and truncation can allow zero required overlap for small sets.Suggested fix
- assertThat(intersection.size()).as("unique connection tuple overlap") - .isGreaterThanOrEqualTo(ffmKeys.size() / 4); + int minOverlap = (int) Math.ceil(ffmKeys.size() * 0.5); + assertThat(intersection.size()).as("unique connection tuple overlap") + .isGreaterThanOrEqualTo(minOverlap);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java` around lines 486 - 487, Update the assertion in NativeComparisonTest that compares intersection.size() to the threshold derived from ffmKeys.size(): replace the current 25% integer-division threshold (ffmKeys.size() / 4) with a 50% threshold and avoid integer truncation by computing half the size using a floating-point operation and taking the ceiling (or otherwise converting to an int safely) so small sets still require at least one element; locate the assertion referencing intersection.size() and ffmKeys to make this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 66-67: The test mutates GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION
via GlobalConfig.set in NativeComparisonTest and does not restore it; capture
the original value before setting (e.g., call
GlobalConfig.get(GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION)), set the
expiration to 0 for the test, and restore the captured original value in an
`@AfterClass` (or equivalent teardown) method so the global config is returned to
its prior state after the test suite completes.
---
Duplicate comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`:
- Around line 465-469: The test currently returns early when both ffmConns and
jnaConns are empty, skipping later validation; change the logic to assert a
non-empty baseline instead of returning: after the equality check on emptiness,
replace the early return with an assertion that jnaConns (or ffmConns) is not
empty (e.g., use assertThat(jnaConns).as("Require non-empty baseline connections
for comparison").isNotEmpty()), so the test fails when both are empty and
continues to perform ratio/overlap/structure checks in NativeComparisonTest
using ffmConns and jnaConns.
- Around line 471-472: The test currently uses a 50% tolerance for connection
count comparison; change the tolerance passed to
assertWithinRatio(ffmConns.size(), jnaConns.size(), 0.50, "connections.size") to
0.25 so the assertion enforces the intended 25% delta between ffmConns.size()
and jnaConns.size() in NativeComparisonTest.java.
- Around line 486-487: Update the assertion in NativeComparisonTest that
compares intersection.size() to the threshold derived from ffmKeys.size():
replace the current 25% integer-division threshold (ffmKeys.size() / 4) with a
50% threshold and avoid integer truncation by computing half the size using a
floating-point operation and taking the ceiling (or otherwise converting to an
int safely) so small sets still require at least one element; locate the
assertion referencing intersection.size() and ffmKeys to make this change.
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`:
- Around line 151-164: The loop can read past pidBuffer because numProcs is
computed from bytes without considering the allocated buffer capacity; clamp
numProcs to the buffer's entry capacity before iterating. Calculate the maximum
entries as bufferSize / Integer.BYTES (or use the constant 1024), then set
numProcs = Math.min(bytes / Integer.BYTES, maxEntries) (also treat negative/zero
bytes defensively) before the for-loop that reads pidBuffer.get(...); this
prevents out-of-bounds reads after calling proc_listpids.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2085081b-d148-4227-9c16-b1c30178f54c
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-03T18:44:48.200Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:48.200Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
🔇 Additional comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)
419-452: Nice strengthening of cumulative TCP/UDP counter assertions.These checks are a solid upgrade over non-null-only validation and better exercise parity between JNA and FFM.
| // Disable memoization so each call gets fresh data for accurate comparison | ||
| GlobalConfig.set(GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION, 0); |
There was a problem hiding this comment.
Restore memoizer config after this test class.
Line 67 mutates a global setting and never restores it, which can leak into later tests in the same JVM and change their behavior.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java`
around lines 66 - 67, The test mutates
GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION via GlobalConfig.set in
NativeComparisonTest and does not restore it; capture the original value before
setting (e.g., call
GlobalConfig.get(GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION)), set the
expiration to 0 for the test, and restore the captured original value in an
`@AfterClass` (or equivalent teardown) method so the global config is returned to
its prior state after the test suite completes.
6829829 to
782967a
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
155-155: Debug instrumentation uses WARN level.The
[CONNDBG]logging at Lines 155, 178-179, and 181-182 is clearly temporary debug instrumentation. UsingLOG.warnwill pollute production logs—consider switching toLOG.debugor removing before merge if this is purely for development diagnostics.♻️ Suggested change
- LOG.warn("[CONNDBG] proc_listpids returned {} bytes, {} procs", bytes, numProcs); + LOG.debug("[CONNDBG] proc_listpids returned {} bytes, {} procs", bytes, numProcs); ... - LOG.warn("[CONNDBG] returning {} connections, socketFds={}, ipcParsed={}", conns.size(), totalSocketFds, - totalIpc); + LOG.debug("[CONNDBG] returning {} connections, socketFds={}, ipcParsed={}", conns.size(), totalSocketFds, + totalIpc); ... - LOG.warn("[CONNDBG] caught exception in getConnections: {}", + LOG.debug("[CONNDBG] caught exception in getConnections: {}",Also applies to: 178-179, 181-182
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java` at line 155, The "[CONNDBG]" debug instrumentation currently uses LOG.warn in MacInternetProtocolStatsFFM (see occurrences with LOG.warn and the literal "[CONNDBG]") which will clutter production logs; change these calls to LOG.debug (or remove them if they are purely temporary) for all occurrences (the calls around proc_listpids and the other two debug lines) so they only emit when debug-level logging is enabled and do not surface as warnings in production.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`:
- Around line 212-231: The static connDbgCount used in queryIPConnection is not
thread-safe and never resets; replace it with a thread-safe counter (e.g.,
change connDbgCount to a private static final AtomicInteger and use
connDbgCount.get() for checks and connDbgCount.getAndIncrement() when
incrementing) or remove the counter/logging entirely; update all references in
queryIPConnection (including the checks before LOG.warn and the connDbgCount++
increment) to use the AtomicInteger methods so concurrent calls from
getConnections() are safe and predictable.
- Around line 223-231: The retry with a larger buffer is currently guarded by
connDbgCount causing retries to stop after three global failures; modify the
logic in MacInternetProtocolStatsFFM (around the proc_pidfdinfo call that uses
socketInfo and size 1024) so the retry call ret = proc_pidfdinfo(pid, fd,
PROC_PIDFDSOCKETINFO, socketInfo, 1024) always executes when ret <= 0, but keep
the LOG.warn("[CONNDBG] retry with size=1024: ret={}", ret) and the
LOG.warn("[CONNDBG] size mismatch, skipping") logging gated by connDbgCount (and
increment connDbgCount where appropriate) so only the logging is limited while
the retry behavior is unconditional.
---
Nitpick comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`:
- Line 155: The "[CONNDBG]" debug instrumentation currently uses LOG.warn in
MacInternetProtocolStatsFFM (see occurrences with LOG.warn and the literal
"[CONNDBG]") which will clutter production logs; change these calls to LOG.debug
(or remove them if they are purely temporary) for all occurrences (the calls
around proc_listpids and the other two debug lines) so they only emit when
debug-level logging is enabled and do not surface as warnings in production.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 40af443e-bfbd-4881-923f-2ed1e3e116ad
📒 Files selected for processing (2)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Codacy Static Code Analysis
- 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 11, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (10)
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-03T18:44:48.200Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:48.200Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
Applied to files:
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java
🔇 Additional comments (7)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (6)
66-67: Global config not restored after test class.The memoizer expiration is set to 0 but never restored, which can affect other tests running in the same JVM. Consider capturing the original value and restoring it in an
@AfterAllmethod.
471-472: Size tolerance is 50%, PR objective states 25%.The
assertWithinRatiocall uses0.50but the PR objective states "Checks connection counts are within a 25% ratio."
486-487: Overlap threshold is 25%, PR objective states 50%.
ffmKeys.size() / 4enforces 25% overlap, but the PR objective states "Verifies at least 50% overlap." Integer division also means small sets (< 4 elements) would require 0 overlap.
418-453: LGTM!The cumulative counter comparisons are well-structured. FFM is called second, so asserting
>=for sent/received counters is the right approach. Both IPv4 and IPv6 paths now have complete coverage including received counters.
489-495: LGTM!The structural validation correctly verifies the key invariants of
IPConnectionobjects: non-empty type string, valid port ranges (0–65535), and non-null state. This aligns well with theIPConnectionclass definition.
465-469: Emptiness agreement check is reasonable.This approach—asserting both agree on emptiness and returning early if empty—is a valid alternative to explicitly asserting JNA is non-empty. It gracefully handles environments where no connections are available while still validating parity.
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java (1)
188-210: LGTM!The refactored
queryFdListcorrectly usesactualSizefrom the secondproc_pidinfocall to determine iteration bounds, and properly accepts theArenaparameter for buffer allocation.
| private static int connDbgCount = 0; | ||
|
|
||
| private static IPConnection queryIPConnection(int pid, int fd, Arena arena) { | ||
| try { | ||
| // Allocate extra space in case FFM layout size differs from kernel expectation | ||
| int layoutSize = (int) SOCKET_FD_INFO.byteSize(); | ||
| MemorySegment socketInfo = arena.allocate(Math.max(layoutSize, 1024), 8); | ||
| int ret = proc_pidfdinfo(pid, fd, PROC_PIDFDSOCKETINFO, socketInfo, layoutSize); | ||
| if (connDbgCount < 5) { | ||
| LOG.warn("[CONNDBG] queryIPConnection pid={} fd={} ret={} expected={}", pid, fd, ret, layoutSize); | ||
| } | ||
| if (ret <= 0) { | ||
| // Try with a larger size in case our layout is too small | ||
| if (connDbgCount < 3) { | ||
| ret = proc_pidfdinfo(pid, fd, PROC_PIDFDSOCKETINFO, socketInfo, 1024); | ||
| LOG.warn("[CONNDBG] retry with size=1024: ret={}", ret); | ||
| } | ||
| if (connDbgCount++ < 5) { | ||
| LOG.warn("[CONNDBG] size mismatch, skipping"); | ||
| } |
There was a problem hiding this comment.
Static debug counter is not thread-safe.
connDbgCount is incremented without synchronization from queryIPConnection, which can be called concurrently from multiple threads (each calling getConnections()). The counter also never resets, so logging will permanently stop after 5 increments across the JVM lifetime.
If this instrumentation is temporary for debugging, this is likely fine. If it's intended to stay, consider using AtomicInteger or removing the counter entirely.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`
around lines 212 - 231, The static connDbgCount used in queryIPConnection is not
thread-safe and never resets; replace it with a thread-safe counter (e.g.,
change connDbgCount to a private static final AtomicInteger and use
connDbgCount.get() for checks and connDbgCount.getAndIncrement() when
incrementing) or remove the counter/logging entirely; update all references in
queryIPConnection (including the checks before LOG.warn and the connDbgCount++
increment) to use the AtomicInteger methods so concurrent calls from
getConnections() are safe and predictable.
| if (ret <= 0) { | ||
| // Try with a larger size in case our layout is too small | ||
| if (connDbgCount < 3) { | ||
| ret = proc_pidfdinfo(pid, fd, PROC_PIDFDSOCKETINFO, socketInfo, 1024); | ||
| LOG.warn("[CONNDBG] retry with size=1024: ret={}", ret); | ||
| } | ||
| if (connDbgCount++ < 5) { | ||
| LOG.warn("[CONNDBG] size mismatch, skipping"); | ||
| } |
There was a problem hiding this comment.
Retry logic is coupled to debug counter.
The retry with size=1024 (Lines 225-227) only executes when connDbgCount < 3. After 3 failures across all PIDs/FDs in the JVM lifetime, retries stop happening. This seems unintended—the retry should probably be unconditional (or always skipped), with only the logging gated by the counter.
🔧 Suggested fix to separate retry from logging
if (ret <= 0) {
- // Try with a larger size in case our layout is too small
- if (connDbgCount < 3) {
- ret = proc_pidfdinfo(pid, fd, PROC_PIDFDSOCKETINFO, socketInfo, 1024);
- LOG.warn("[CONNDBG] retry with size=1024: ret={}", ret);
- }
- if (connDbgCount++ < 5) {
- LOG.warn("[CONNDBG] size mismatch, skipping");
+ // Try with a larger size in case our layout is too small
+ ret = proc_pidfdinfo(pid, fd, PROC_PIDFDSOCKETINFO, socketInfo, 1024);
+ if (connDbgCount++ < 5) {
+ LOG.debug("[CONNDBG] retry with size=1024: ret={}", ret);
+ }
+ if (ret <= 0) {
+ return null;
}
- return null;
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java`
around lines 223 - 231, The retry with a larger buffer is currently guarded by
connDbgCount causing retries to stop after three global failures; modify the
logic in MacInternetProtocolStatsFFM (around the proc_pidfdinfo call that uses
socketInfo and size 1024) so the retry call ret = proc_pidfdinfo(pid, fd,
PROC_PIDFDSOCKETINFO, socketInfo, 1024) always executes when ret <= 0, but keep
the LOG.warn("[CONNDBG] retry with size=1024: ret={}", ret) and the
LOG.warn("[CONNDBG] size mismatch, skipping") logging gated by connDbgCount (and
increment connDbgCount where appropriate) so only the logging is limited while
the retry behavior is unconditional.
The internetProtocolStats test was a stub that only checked stats objects were non-null. Expand it to: - Compare TCP/UDP stats cumulative counters (FFM >= JNA for segments sent/received, datagrams sent/received) across v4 and v6 - Compare connection lists: verify FFM returns connections, check size ratio, verify at least 50% overlap by (type, localPort, foreignPort) tuple matching, and validate structural correctness of all FFM connections (type, port range, state non-null) This exercises the previously untested queryTCPv4/v6Connections and queryUDPv4/v6Connections methods in IPHlpAPIUtilFFM (Windows) and the connection parsing in MacInternetProtocolStatsFFM (macOS).
782967a to
bffeb48
Compare
The
internetProtocolStats()comparison test was a stub that only verified stats objects were non-null. This left the entire connection-querying codepath untested in the FFM module —queryTCPv4Connections,queryTCPv6Connections,queryUDPv4Connections,queryUDPv6ConnectionsinIPHlpAPIUtilFFM(Windows, 162 missed lines) and the connection parsing inMacInternetProtocolStatsFFM(macOS, 107 missed lines).Changes:
internetProtocolStats()now compares:New
internetProtocolConnections()test:Coverage impact:
This should significantly improve coverage for:
IPHlpAPIUtilFFM(Windows): 162 missed → exercises all 4 query methods +stateLookupMacInternetProtocolStatsFFM(macOS): 107 missed → exercisesgetConnections,parseConnection,stateLookupWindowsInternetProtocolStatsFFM: exercisesgetConnectionsdelegationNetStatFFM(macOS driver): exercises TCP/UDP stats queriesSummary by CodeRabbit
Tests
Refactor