Repository navigation
Hoist the MacDisplay CoreFoundation helpers into CFUtil/CFUtilFFM - #3570
Conversation
MacDisplayJNA carried five private CoreFoundation helpers. Two kinds of duplication were hiding there: cfDictGetDictionary/String/Long are general CFDictionary accessors, and MacDisplayFFM had its own copy of each. Move them to CFUtil as getDictionary/getString/getLong, where they are reachable from a test. cfRegistryEntryGetLong/String were reimplementing jna-platform's built-in IORegistryEntry.getLongProperty/getStringProperty, which the FFM twin was already calling. Drop them and call the built-ins, which removes the duplication and aligns the two implementations on one property-read path. CFUtilTest covers the new accessors against a real CFDictionary. Note that the dictionary has to be created with the CFEqual-based type callbacks: with null callbacks CoreFoundation matches keys by pointer identity, so a freshly created CFStringRef for the same text would not hit. Verified on an Apple Silicon host with an external monitor and the built-in panel; both displays are still reported, with the synthesized built-in entry exercising every hoisted method.
The FFM twin of the preceding commit. MacDisplayFFM had its own private cfDictGetDictionary/String/Long, duplicating the JNA copies; move them to CFUtilFFM as getDictionary/getString/getLong so both implementations read CFDictionary values through one tested helper per backend. These cannot be shared in oshi-common, which may not reference FFM or JNA types, so each backend keeps its own CF utility class. CFUtilFFMTest mirrors CFUtilTest, including the CFEqual-based dictionary callbacks. The new test package needs an --add-opens entry in module-info.test, since tests run patched into the module.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
🧰 Additional context used📓 Path-based instructions (6)**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/test/java/**/*Test.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core/src/test/java/**/*Test.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (5)📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-07-30T00:35:22.638ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-08-03T00:46:14.953ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (7)
📝 WalkthroughWalkthroughChangesCoreFoundation display integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant MacDisplayFFM
participant CFUtilFFM
participant CoreFoundation
MacDisplayFFM->>CFUtilFFM: Read product attributes
CFUtilFFM->>CoreFoundation: Query CFDictionaryRef
CoreFoundation-->>CFUtilFFM: Return borrowed value
CFUtilFFM-->>MacDisplayFFM: Return converted value or null
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3570 +/- ##
============================================
+ Coverage 79.52% 79.64% +0.11%
- Complexity 3818 4176 +358
============================================
Files 709 709
Lines 24248 24227 -21
Branches 4052 4050 -2
============================================
+ Hits 19284 19295 +11
+ Misses 2781 2745 -36
- Partials 2183 2187 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The getString/getLong helpers hoisted in #3570 were copied from the JNA twin verbatim, wrapping the borrowed CFDictionaryGetValue result in `new CFStringRef(v)` / `new CFNumberRef(v)` just to read a value. In FFM CFTypeRef is AutoCloseable, so that reintroduces the exact shape #3298 removed when it added the static borrowed-segment accessors and migrated 45 call sites to them. SonarCloud flagged both as S2095 blockers. Switch to CFStringRef.stringValue(MemorySegment) and CFNumberRef.longValue(MemorySegment), matching cfPointerToString a few lines above. There was no leak to fix: these are borrowed references under the CF Get Rule and must not be released, so actually closing them as the rule literally suggests would over-release memory OSHI does not own. The constructors' type-ID check is dropped, which is the tradeoff the other migrated sites already accepted; a soft "" / 0 fallback via getOrDefault is preferable here to a ClassCastException escaping MacDisplayFFM.synthesize. The JNA CFUtil twin is intentionally left alone: its CFTypeRef is a PointerType, not AutoCloseable, so the idiom is correct there and it has no static accessors to switch to. Verified on macOS (JDK 26): CFUtilFFMTest testGetString/testGetLong run and pass, and SystemInfoTest still enumerates both the external and the built-in display, whose synthesize() path calls both methods.
Summary
MacDisplayJNAandMacDisplayFFMare among the highest-uncovered classes on Codecov, because CI has no display hardware to exercise them. Sitting inside them were several general-purpose CoreFoundation helpers that were untestable only by virtue of where they lived. This moves them out to the per-backend CF utility class.Two distinct kinds of duplication were in there, and they get different treatment:
cfDictGet{Dictionary,String,Long}— general CFDictionary accessors, with a full copy in each twin. Hoisted toCFUtil.getDictionary/getString/getLong(JNA) andCFUtilFFM.*(FFM). They can't go tooshi-common, which may not reference JNA or FFM types, so one utility class per backend is as far as they can travel.cfRegistryEntryGetLong/cfRegistryEntryGetString(JNA only) — these were reimplementing jna-platform's built-inIORegistryEntry.getLongProperty/getStringProperty, which the FFM twin was already calling. Deleted in favor of the built-ins. That removes the duplication and closes a quiet twin divergence: both implementations now read registry properties through the same path.Net:
MacDisplayJNA−97/+15,MacDisplayFFM−38/+9, with the shared logic in one tested place per backend.The JNA and FFM sides are committed separately so
NativeComparisonTesthas a chance to flag drift between them, rather than a symmetric change passing silently.Tests
CFUtilTestandCFUtilFFMTestbuild a real native CFDictionary and round-trip values through the new accessors.One subtlety worth recording for whoever writes the next CF test: the dictionary must be created with the CFEqual-based
kCFTypeDictionaryKeyCallBacks/kCFTypeDictionaryValueCallBacks. Withnullcallbacks CoreFoundation matches keys by pointer identity, so a freshly createdCFStringReffor the same text does not hit — and the string cases can pass anyway on interning luck while the dictionary case fails. The FFM test package also needed an--add-opensline inmodule-info.test.Verification
Ran both
SystemInfoTestentry points on an Apple Silicon host with an external monitor plus the built-in panel. Both displays are reported on both paths, and the two display sections are byte-for-byte identical:This covers the changed code end to end: Display 0 comes through the real-EDID path, and Display 1 is the synthesized built-in panel, which exercises every hoisted method —
getDictionaryresolvingProductAttributes,getLong/getStringpulling the fields out of it, and the jna-platform built-ins producing the native resolution and name.Full gate green on macOS / JDK 25: spotless, checkstyle,
clean installwith tests (0 failed), forbiddenapis, javadoc. Intel Mac and the pre-Apple-SiliconIODisplayConnectpath are unverified — I have no Intel hardware.No CHANGELOG entry: pure refactor plus test-only additions, no user-visible behavior change.
Context
This is likely the first of a few. The same pattern — a utility-shaped helper buried in a focused class, untested because its host can't run on CI — shows up elsewhere; the parse helpers in the command-line-processing drivers look like the next candidates. Happy to split those off separately.
Summary by CodeRabbit
Bug Fixes
Refactor
Tests