Repository navigation
Fix WrongMethodTypeException for void invokeExact in expression lambdas - #3302
Conversation
MethodHandle.invokeExact() is signature-polymorphic: its return type is inferred from the call-site context. In an expression lambda passed to a void-returning functional interface, the compiler infers Object as the return type instead of void, causing a WrongMethodTypeException at runtime. Convert expression lambdas to block lambdas so invokeExact() is in a statement context where its return type is correctly inferred as void. Fixes #3301
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📜 Recent 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)
🔇 Additional comments (2)
📝 WalkthroughWalkthroughTwo COM wrapper methods in the FFM API now use multi-line block-bodied lambdas instead of single-line expressions when invoking method handles through ChangesCOM FFM Lambda Block Formatting
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3302 +/- ##
============================================
- Coverage 76.19% 76.05% -0.14%
Complexity 76 76
============================================
Files 410 410
Lines 15830 15830
Branches 2546 2546
============================================
- Hits 12061 12039 -22
- Misses 2274 2286 +12
- Partials 1495 1505 +10
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:
|
…#3424) * Fix WrongMethodTypeException in BStrFFM.free void invokeExact (#3422) SysFreeString is a void downcall, so its handle type is (MemorySegment)void. MethodHandle.invokeExact is signature-polymorphic and infers its return type from the call site; in an expression lambda passed to the void-returning runOrLog(ThrowingRunnable), javac infers Object instead of void, so the call site's (MemorySegment)Object does not match the handle and throws WrongMethodTypeException at runtime (swallowed at DEBUG, leaking the BSTR). Convert to a block lambda so invokeExact is in a statement context and its return type is inferred as void. This reinstates the fix from #3302, which was lost when the FFM code moved from oshi.ffm.windows.com to oshi.ffm.platform.windows.com; a comment now marks why the block form matters. Fixes #3422 * Add source-policy test guarding against void invokeExact regression The WrongMethodTypeException from a void invokeExact in an expression lambda only surfaces on the native platform and is swallowed by runOrLog, so no ordinary unit test can observe it -- and it has already regressed twice when the FFM code was moved between packages (#3301, #3422). VoidInvokeExactSourceTest scans oshi-core-ffm's main sources for the expression-lambda form and fails with the offending file:line, so the regression is caught on every build (including non-Windows CI). Verified it fails on the pre-fix form and passes on the block-lambda fix. * Suppress S1602 on BStrFFM.free block lambda; scan multi-line; CHANGELOG - Add // NOSONAR (java:S1602) on the BStrFFM.free block lambda so a future Sonar S1602 sweep can't collapse it back to the expression form that reintroduced #3422. It is the only single-statement void invokeExact block lambda; the other runOrLog/runSilently blocks are multi-statement, and Ole32FFM.CoUninitialize is a safe no-arg method reference. - VoidInvokeExactSourceTest now scans whole-file content (bounded to a single statement with [^{};]*) so an expression lambda wrapped across lines is also caught, not just single-line occurrences. - Add CHANGELOG entry.
Summary
MethodHandle.invokeExact()is signature-polymorphic: its return type is inferred from the call-site context. In an expression lambda passed to a void-returning functional interface (ThrowingRunnable), the compiler infersObjectas the return type instead ofvoid, causing aWrongMethodTypeExceptionat runtime.Fix
Convert expression lambdas to block lambdas so
invokeExact()is in a statement context where its return type is correctly inferred asvoid.Affected methods
Ole32FFM.CoUninitialize()— reported in handle's method type ()void but found ()Object on windows when getFileStores with FFM #3301BStrFFM.free()— same latent bugWhy CI didn't catch it
The
runOrLog()helper catchesThrowableand logs at DEBUG level, so the test passed silently while the COM cleanup actually failed.Fixes #3301
Summary by CodeRabbit