Repository navigation
Add CoreFoundation FFM tests for all wrapper types - #3163
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:
📝 WalkthroughWalkthroughAdds macOS JUnit 5 integration tests for CoreFoundation FFM wrappers, introduces a native CFHash downcall and hashCode fallback, updates test JVM args to open Changes
Sequence Diagram(s)sequenceDiagram
participant Test as JUnit Test
participant CF as CoreFoundation.CFTypeRef
participant CFN as CoreFoundationFunctions
participant Native as macOS CoreFoundation
Test->>CF: construct/get wrapper (MemorySegment)
CF->>CFN: call CFHash(segment) (hashCode)
alt CFHash succeeds
CFN->>Native: downcall CFHash(segment)
Native-->>CFN: return hash (long)
CFN-->>CF: return value
CF-->>Test: hashCode -> Long.hashCode(value)
else CFHash throws
CFN-->>CF: throw
CF-->>Test: fall back to Objects.hash(segment())
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3163 +/- ##
==========================================
- Coverage 58.43% 57.80% -0.63%
==========================================
Files 362 316 -46
Lines 20231 17392 -2839
Branches 3306 3069 -237
==========================================
- Hits 11821 10053 -1768
+ Misses 6785 5862 -923
+ Partials 1625 1477 -148
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-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (1)
70-84:testCFTypeRefEqualsAndHashCodecurrently validates onlyequals().Please add positive
hashCode()contract assertions for equal instances (including null-wrapper equality case) so the method name and coverage match.♻️ Suggested test additions
try { assertThat(str1.equals(str2), is(true)); + assertThat(str1.hashCode(), is(str2.hashCode())); assertThat(str1.equals(str3), is(false)); assertThat(str1.equals(null), is(false)); assertThat(str1.equals(str1), is(true)); // Null refs are equal to each other var nullRef1 = new CFTypeRef(NULL); var nullRef2 = new CFTypeRef(NULL); assertThat(nullRef1.equals(nullRef2), is(true)); + assertThat(nullRef1.hashCode(), is(nullRef2.hashCode())); assertThat(nullRef1.equals(str1), is(false));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java` around lines 70 - 84, Add assertions verifying the hashCode contract in testCFTypeRefEqualsAndHashCode: for equal CFStringRef instances created via CFStringRef.createCFString("test") assert their hashCode() values are equal, for unequal instances (e.g., "test" vs "other") assert hashCodes are likely different (or at least not relied upon), and for the null-wrapper case (new CFTypeRef(NULL) vs new CFTypeRef(NULL)) assert their hashCode() values are equal; place these assertions alongside the existing equals() assertions in the same try/finally block so the test name and coverage reflect both equals() and hashCode().
🤖 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-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java`:
- Around line 437-438: The test leaks two native CFStringRef instances because
CFStringRef.createCFString("val") is called and then dict.setValue(null, ...)
returns early without releasing them; update the null-key test around
dict.setValue(...) to capture the created CFStringRef objects into local
variables (e.g., CFStringRef keyRef1/keyRef2 and valueRef1/valueRef2) and ensure
each created ref is explicitly released (via the appropriate CF release/dispose
method used elsewhere in the project) in a finally block or immediately after
the setValue call when the key is null so no native refs remain leaked;
reference CFStringRef.createCFString and dict.setValue to locate the fix.
- Around line 95-101: The test currently relies on exact CFGetRetainCount values
(CoreFoundationFunctions.CFGetRetainCount) around str.retain() and
str.release(), which is flaky; remove the exact equal assertions and instead
verify retain/release behavior without asserting precise counts—for example,
check that calling str.retain() does not throw and that str.release() eventually
allows cleanup (or assert that retain count is >0 before release or use
boolean/exception-based semantics), replacing the is(countBefore + 1) and
is(countBefore) assertions with non-exact checks or behavioral assertions using
the CoreFoundation wrapper methods (str.retain, str.release, and
CFGetRetainCount only for non-exact comparisons like greater-than/positive) so
the test no longer depends on exact retain-count deltas.
---
Nitpick comments:
In `@oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java`:
- Around line 70-84: Add assertions verifying the hashCode contract in
testCFTypeRefEqualsAndHashCode: for equal CFStringRef instances created via
CFStringRef.createCFString("test") assert their hashCode() values are equal, for
unequal instances (e.g., "test" vs "other") assert hashCodes are likely
different (or at least not relied upon), and for the null-wrapper case (new
CFTypeRef(NULL) vs new CFTypeRef(NULL)) assert their hashCode() values are
equal; place these assertions alongside the existing equals() assertions in the
same try/finally block so the test name and coverage reflect both equals() and
hashCode().
🪄 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: 058d157f-661e-4450-bef4-5b9244414514
📒 Files selected for processing (2)
oshi-core-java25/src/test/java/module-info.testoshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.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, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 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-core-java25/src/test/java/module-info.test
📚 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-core-java25/src/test/java/module-info.test
🔇 Additional comments (2)
oshi-core-java25/src/test/java/module-info.test (1)
9-10: Correct JPMS test access update for macOS FFM tests.Opening
com.github.oshi/oshi.ffm.mactoorg.junit.platform.commonsis the right test-side change for reflective discovery/invocation of the new package-private JUnit class.oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (1)
41-43: Great test guardrails and breadth for native wrapper coverage.The OS/JRE gating and broad real-call coverage across wrapper types look solid for this suite.
Also applies to: 149-553
f4305c9 to
3906668
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (1)
93-103:⚠️ Potential issue | 🟠 MajorRemove exact retain-count assertions; this is flaky by CoreFoundation contract.
At Line 97 and Line 100/103, the test asserts precise
CFGetRetainCountdeltas. This is not stable and can fail nondeterministically. Keep behavioral retain/release validation without exact count math.What do Apple CoreFoundation docs say about CFGetRetainCount reliability, and do they recommend asserting exact retain-count deltas in automated tests?Proposed change
`@Test` void testCFTypeRefRetainRelease() throws Throwable { var str = CFStringRef.createCFString("retain-test"); try { - long countBefore = CoreFoundationFunctions.CFGetRetainCount(str.segment()); str.retain(); - long countAfter = CoreFoundationFunctions.CFGetRetainCount(str.segment()); - assertThat(countAfter, is(countBefore + 1)); - // Release the extra retain str.release(); - assertThat(CoreFoundationFunctions.CFGetRetainCount(str.segment()), is(countBefore)); + assertThat(str.isNull(), is(false)); + assertThat(str.isTypeID(CoreFoundationFunctions.STRING_TYPE_ID), is(true)); } finally { str.release(); } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java` around lines 93 - 103, The test testCFTypeRefRetainRelease relies on exact values from CoreFoundationFunctions.CFGetRetainCount which is flaky; modify the test to avoid exact retain-count arithmetic: after creating the CFStringRef via CFStringRef.createCFString("retain-test") call str.retain() and assert that CFGetRetainCount(str.segment()) is greater than or equal to the prior value (or simply greater than when possible), then call str.release() and assert the count is not greater than the retained value (or that it returns to a non-increased state) — in short replace strict equality assertions around CoreFoundationFunctions.CFGetRetainCount with non-exact comparisons or behavioral checks (no-op safety of str.release) referencing testCFTypeRefRetainRelease, CFStringRef.createCFString, CoreFoundationFunctions.CFGetRetainCount, str.retain, and str.release.
🧹 Nitpick comments (1)
oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (1)
170-267: Consider parameterizing numeric conversion tests to reduce duplication.The
CFNumbertests are solid, but this block is highly repetitive and could be collapsed into parameterized cases for easier maintenance.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java` around lines 170 - 267, The test methods testCFNumberLong/testCFNumberInt/testCFNumberShort/testCFNumberByte/testCFNumberDouble/testCFNumberFloat should be consolidated into a single parameterized JUnit test that iterates over cases (type id, ValueLayout constant, input value, expected accessor and expected assertion), calling CoreFoundationFunctions.CFNumberCreate and wrapping the result in CFNumberRef for each case; use method sources or `@ParameterizedTest` with a stream of tuples (e.g., (CoreFoundation.kCFNumberLongLongType, ValueLayout.JAVA_LONG, 123456789L, cfNum::longValue, 123456789L)) to avoid duplication while ensuring cfNum.release() runs in finally for each iteration and assertions use appropriate matchers (is/closeTo) per type.
🤖 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-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java`:
- Around line 93-103: The test testCFTypeRefRetainRelease relies on exact values
from CoreFoundationFunctions.CFGetRetainCount which is flaky; modify the test to
avoid exact retain-count arithmetic: after creating the CFStringRef via
CFStringRef.createCFString("retain-test") call str.retain() and assert that
CFGetRetainCount(str.segment()) is greater than or equal to the prior value (or
simply greater than when possible), then call str.release() and assert the count
is not greater than the retained value (or that it returns to a non-increased
state) — in short replace strict equality assertions around
CoreFoundationFunctions.CFGetRetainCount with non-exact comparisons or
behavioral checks (no-op safety of str.release) referencing
testCFTypeRefRetainRelease, CFStringRef.createCFString,
CoreFoundationFunctions.CFGetRetainCount, str.retain, and str.release.
---
Nitpick comments:
In `@oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java`:
- Around line 170-267: The test methods
testCFNumberLong/testCFNumberInt/testCFNumberShort/testCFNumberByte/testCFNumberDouble/testCFNumberFloat
should be consolidated into a single parameterized JUnit test that iterates over
cases (type id, ValueLayout constant, input value, expected accessor and
expected assertion), calling CoreFoundationFunctions.CFNumberCreate and wrapping
the result in CFNumberRef for each case; use method sources or
`@ParameterizedTest` with a stream of tuples (e.g.,
(CoreFoundation.kCFNumberLongLongType, ValueLayout.JAVA_LONG, 123456789L,
cfNum::longValue, 123456789L)) to avoid duplication while ensuring
cfNum.release() runs in finally for each iteration and assertions use
appropriate matchers (is/closeTo) per type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4b9a70ec-1d3a-4788-b873-79905c875ae5
📒 Files selected for processing (2)
oshi-core-java25/src/test/java/module-info.testoshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java
✅ Files skipped from review due to trivial changes (1)
- oshi-core-java25/src/test/java/module-info.test
📜 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: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
🔇 Additional comments (3)
oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (3)
41-43: Good platform/runtime gating for native tests.
@EnabledOnOs(OS.MAC)+@EnabledForJreRange(min = JRE.JAVA_25)is the right guardrail for this FFM/CoreFoundation suite.
430-448: Nice fix for native resource cleanup in null-key dictionary test.Capturing and releasing
val1/val2infinallyavoids leaking CF objects on the null-key path.
514-562: Great negative-path coverage for wrapper cast safety.These
ClassCastExceptiontests materially strengthen type-safety guarantees across wrappers.
3906668 to
8272208
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java`:
- Around line 75-77: The test fails the equals/hashCode contract because
CFTypeRef.equals() uses CFEqual(value) but CFTypeRef.hashCode() uses segment
identity; update CFTypeRef.hashCode() in CoreFoundation.java to return a
value-based hash by calling the native CFHash for the underlying CFType (e.g.,
add or use a CoreFoundation.CFHash(Pointer) native wrapper or
CoreFoundation.INSTANCE.CFHash(ref) and convert its result to int), handle nulls
consistently, and ensure the implementation mirrors CFTypeRef.equals() semantics
so equal CF values produce equal hash codes.
🪄 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: 25fc2133-0b8a-4650-a1ca-12b05c4feba8
📒 Files selected for processing (3)
oshi-core-java25/src/test/java/module-info.testoshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.javapom.xml
✅ Files skipped from review due to trivial changes (1)
- oshi-core-java25/src/test/java/module-info.test
📜 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). (1)
- GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (3)
📓 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:15.707Z
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-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:
pom.xml
📚 Learning: 2026-04-15T04:56:15.707Z
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:15.707Z
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-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java
🔇 Additional comments (3)
oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (2)
97-103: Retain-count delta checks are appropriate in this test scope.This is a good, targeted ownership assertion for freshly created refs held solely by the test.
Based on learnings: asserting exact
CFGetRetainCountdeltas here is intentional and reliable for exclusively owned, freshly created CF objects.
439-447: Good native cleanup on ignored-null-key path.
val1andval2are now explicitly released infinally, which prevents leaking CFString refs whensetValueignores null keys.pom.xml (1)
801-807: The FFM exclusion at line 805 is pre-existing and not a change in this PR. This review comment is based on an incorrect premise.> Likely an incorrect or invalid review comment.
35 tests covering CFTypeRef, CFStringRef, CFNumberRef, CFBooleanRef, CFDataRef, CFArrayRef, CFDictionaryRef, CFMutableDictionaryRef, CFAllocatorRef, CFLocale, and CFDateFormatter. Tests exercise null handling, roundtrip conversions, retain/release, equals, type ID checks, and ClassCastException paths. All gated by @EnabledOnOs(MAC) and @EnabledForJreRange(min = JAVA_25).
02aca10 to
9832bd0
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (1)
70-90: Consider adding one test for thehashCode()fallback branch.This covers null/happy paths well; adding a targeted case for the
CFHash-throws fallback would lock in the resilience behavior too.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java` around lines 70 - 90, Add a unit test that exercises CFTypeRef.hashCode's fallback when the native CFHash call throws: create a CFStringRef (e.g., via CFStringRef.createCFString("fallback")), use a Mockito/spy on CoreFoundation.CFHash (or the native wrapper method used by CFTypeRef.hashCode) to throw a runtime exception for that object, then assert CFTypeRef.hashCode() returns the fallback value (e.g., System.identityHashCode(ref) or whatever the fallback implementation uses) and does not propagate the exception; reference CFTypeRef.hashCode, CFStringRef.createCFString, and CoreFoundation.CFHash in the test.
🤖 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-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java`:
- Around line 70-90: Add a unit test that exercises CFTypeRef.hashCode's
fallback when the native CFHash call throws: create a CFStringRef (e.g., via
CFStringRef.createCFString("fallback")), use a Mockito/spy on
CoreFoundation.CFHash (or the native wrapper method used by CFTypeRef.hashCode)
to throw a runtime exception for that object, then assert CFTypeRef.hashCode()
returns the fallback value (e.g., System.identityHashCode(ref) or whatever the
fallback implementation uses) and does not propagate the exception; reference
CFTypeRef.hashCode, CFStringRef.createCFString, and CoreFoundation.CFHash in the
test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 760193ad-5317-4e49-afd7-000016a57796
📒 Files selected for processing (5)
oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundation.javaoshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.javaoshi-core-java25/src/test/java/module-info.testoshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.javapom.xml
✅ Files skipped from review due to trivial changes (1)
- pom.xml
🚧 Files skipped from review as they are similar to previous changes (1)
- oshi-core-java25/src/test/java/module-info.test
📜 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). (9)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, windows-latest
- 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: Test JDK 25, macos-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 (4)
📓 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:15.707Z
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-15T04:56:15.707Z
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:15.707Z
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-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.javaoshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundation.javaoshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.
Applied to files:
oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.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-core-java25/src/main/java/oshi/ffm/mac/CoreFoundation.java
🔇 Additional comments (4)
oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.java (1)
61-75: CFHash wrapper addition is clean and consistent.The new native binding and wrapper method follow the same FFM downcall pattern already used throughout this class.
oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundation.java (1)
173-180:CFTypeRef.hashCode()update looks solid.Null returns are now deterministic, and using
CFHashmakes hashing value-oriented while keeping a safe fallback path.oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java (2)
94-106: Retain/release delta assertions are appropriate in this test context.This is a good ownership-semantics check for a freshly created CF object under test control.
Based on learnings, asserting exact
CFGetRetainCountdeltas for freshly created solely-owned CF objects in this test is intentional and reliable.
439-448: Nice fix: temporary CFString refs are now explicitly released.The added
finallycleanup removes native leak risk in the null-key dictionary path.
Summary
Adds 35 tests for all CoreFoundation wrapper types in
CoreFoundation.java, exercising real native CoreFoundation calls on macOS.Changes
CoreFoundationTestwith 35 tests, gated by@EnabledOnOs(OS.MAC)+@EnabledForJreRange(min = JRE.JAVA_25)--add-opensforoshi.ffm.macso JUnit can reflectively access the test classTest Coverage
CFTypeRef (base class)
NULLand Javanull)getTypeID,isTypeIDequals/hashCode(equal strings, different strings, null refs, self-equality)retain/releasewith retain count verificationCFStringRef
CFNumberRef
longValue,intValue,shortValue,byteValue,doubleValue,floatValueroundtrips viaCFNumberCreateCFBooleanRef
kCFBooleanTrue→ true,kCFBooleanFalse→ false (via symbol lookup + reinterpret)CFDataRef
CFDataCreate:getLength,getBytePtr,getBytesCFArrayRef
getCountandgetValueAtIndexCFDictionaryRef / CFMutableDictionaryRef
setValue/getValue/getCount/getValueIfPresent, missing key returns NULLCFAllocatorRef, CFLocale, CFDateFormatter
CFAllocatorGetDefault→ non-nullCFLocale.copyCurrent→ non-nullCFDateFormatter.create+getFormat→ non-empty format stringClassCastException paths
CFNumberRef,CFBooleanRef,CFArrayRef,CFDataRef,CFDictionaryRefall reject a CFString segmentSummary by CodeRabbit