You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
09:49:54.547 [main] DEBUG oshi.ffm.platform.windows.com.BStrFFM -- BStrFFM.free failed
java.lang.invoke.WrongMethodTypeException: handle's method type (MemorySegment)void but found (MemorySegment)Object
at java.base/java.lang.invoke.Invokers.newWrongMethodTypeException(Invokers.java:524)
at java.base/java.lang.invoke.Invokers.checkExactType(Invokers.java:533)
at oshi.ffm.platform.windows.com.BStrFFM.lambda$free$0(BStrFFM.java:72)
at oshi.util.ExceptionUtil.runOrLog(ExceptionUtil.java:497)
at oshi.util.ExceptionUtil.runOrLog(ExceptionUtil.java:484)
at oshi.ffm.platform.windows.com.BStrFFM.free(BStrFFM.java:72)
at oshi.ffm.platform.windows.com.IWbemLocatorFFM.connectServer(IWbemLocatorFFM.java:113)
at oshi.ffm.util.platform.windows.WmiQueryHandlerFFM.queryWMI(WmiQueryHandlerFFM.java:149)
at oshi.ffm.util.platform.windows.WmiQueryExecutorFFM.queryWMI(WmiQueryExecutorFFM.java:57)
at oshi.ffm.util.platform.windows.WmiQueryExecutorFFM.queryWMI(WmiQueryExecutorFFM.java:50)
at oshi.driver.common.windows.wmi.Win32BaseBoard.queryBaseboardInfo(Win32BaseBoard.java:50)
Thanks for the report — confirmed, and there's a fix in #3424.
Root cause:SysFreeString is a void native call, so its method handle type is (MemorySegment)void. MethodHandle.invokeExact is signature-polymorphic and infers its return type from the call site. In the expression-bodied lambda passed to the void-returning runOrLog(...), javac infers Object instead of void, so the call site ((MemorySegment)Object) doesn't match the handle and throws WrongMethodTypeException. It's caught and logged at DEBUG, so it doesn't crash — but the BSTR isn't freed, so there's a small memory leak on each affected WMI query.
This is a regression of #3302 (which fixed #3301). That fix converted this exact line in BStrFFM.free to a block lambda, but it was lost when the FFM code moved from oshi.ffm.windows.com to oshi.ffm.platform.windows.com — the file came back in the old expression-lambda form.
The fix reinstates the block-lambda form (so invokeExact is in a statement context and infers void) and adds a comment so a future move doesn't silently revert it again. I also scanned the rest of oshi-core-ffm and this was the only remaining reintroduction of the pattern.
As a preventative, #3424 also adds a source-policy test (VoidInvokeExactSourceTest) that scans the oshi-core-ffm sources for the expression-lambda invokeExact form and fails the build with the offending file:line.
Because the actual WrongMethodTypeException only fires on the native platform and is swallowed by runOrLog, no ordinary unit test can observe it — and this has now regressed twice on package moves. The source scan runs on every build (including non-Windows CI), so the next reintroduction is caught immediately. Verified it fails on the pre-fix expression-lambda form and passes on the block-lambda fix.
Correction to my note above: the regression was not caused by the FFM package move (#3356 preserved the #3302 fix). It was re-broken by 1d0cb9cf97 "Collapse single-statement block lambdas to expression form (S1602)" — a Sonar mechanical sweep that collapsed the block lambda back to expression form. Worth being aware that Sonar rule S1602 (and its autofix) will reintroduce this footgun on any such lambda; the new source-policy test in #3424 guards against it.
@JaynLau Since you also reported the original (#3301), here's the full story of how it came back and how we're stopping it from happening a third time.
What broke
SysFreeString is a void native call, so its method handle type is (MemorySegment)void. MethodHandle.invokeExact is signature-polymorphic: its return type is inferred from the call site. In an expression-bodied lambda passed to a void-returning helper (runOrLog(...)), javac infers Object instead of void, so the call site ((MemorySegment)Object) no longer matches the handle and throws WrongMethodTypeException. It's caught and logged at DEBUG, so nothing crashes — but the BSTR is never freed, leaking a little memory on each WMI query.
Empirically, for a void handle:
Form
Result
handle::invokeExact (method reference)
OK
() -> handle.invokeExact() (expression lambda)
WrongMethodTypeException
() -> { handle.invokeExact(); } (block lambda)
OK
Why it regressed (it was a Sonar rule, not the package move)
#3302 originally fixed this in two places by using block lambdas: BStrFFM.free and Ole32FFM.CoUninitialize. The later FFM package move (#3356) preserved both. What re-broke it was a Sonar mechanical cleanup (#3394, rules S1602 / S1612):
S1602 ("single-statement lambdas shouldn't use a block") collapsed () -> { … } back to the expression form — exactly the shape that miscompiles a void invokeExact.
Why only one of the two regressed
Ole32FFM.CoUninitialize takes no arguments, so after S1602 collapsed it, S1612 ("use method references") further rewrote it to CoUninitialize::invokeExact — which is the safe form (see table). It came out fine.
BStrFFM.freecaptures an argument (bstr), so it can't become a no-arg method reference. S1602 collapsed it to () -> SysFreeString.invokeExact(bstr) and left it there — the broken expression form you hit.
Add // NOSONAR (java:S1602) on that line so a future S1602 sweep can't collapse it again.
Add a source-policy test (VoidInvokeExactSourceTest) that scans the oshi-core-ffm sources for the runOrLog/runSilently(() -> … invokeExact) expression-lambda form (single- or multi-line) and fails the build with the offending file:line. Because the runtime error only fires on Windows and is swallowed, no ordinary unit test can see it — the source scan runs on every build (including non-Windows CI) and guards both call sites against reintroduction.
Thanks again for the report — the stack trace made this quick to pin down.
Activity
[-]FFM free string faild on windows[/-][+]FFM free string failed on windows[/+]dbwiddis commentedon Jul 1, 2026
Thanks for the report — confirmed, and there's a fix in #3424.
Root cause:
SysFreeStringis avoidnative call, so its method handle type is(MemorySegment)void.MethodHandle.invokeExactis signature-polymorphic and infers its return type from the call site. In the expression-bodied lambda passed to the void-returningrunOrLog(...), javac infersObjectinstead ofvoid, so the call site ((MemorySegment)Object) doesn't match the handle and throwsWrongMethodTypeException. It's caught and logged at DEBUG, so it doesn't crash — but the BSTR isn't freed, so there's a small memory leak on each affected WMI query.This is a regression of #3302 (which fixed #3301). That fix converted this exact line in
BStrFFM.freeto a block lambda, but it was lost when the FFM code moved fromoshi.ffm.windows.comtooshi.ffm.platform.windows.com— the file came back in the old expression-lambda form.The fix reinstates the block-lambda form (so
invokeExactis in a statement context and infersvoid) and adds a comment so a future move doesn't silently revert it again. I also scanned the rest ofoshi-core-ffmand this was the only remaining reintroduction of the pattern.dbwiddis commentedon Jul 1, 2026
As a preventative, #3424 also adds a source-policy test (
VoidInvokeExactSourceTest) that scans theoshi-core-ffmsources for the expression-lambdainvokeExactform and fails the build with the offendingfile:line.Because the actual
WrongMethodTypeExceptiononly fires on the native platform and is swallowed byrunOrLog, no ordinary unit test can observe it — and this has now regressed twice on package moves. The source scan runs on every build (including non-Windows CI), so the next reintroduction is caught immediately. Verified it fails on the pre-fix expression-lambda form and passes on the block-lambda fix.dbwiddis commentedon Jul 1, 2026
Correction to my note above: the regression was not caused by the FFM package move (#3356 preserved the #3302 fix). It was re-broken by
1d0cb9cf97"Collapse single-statement block lambdas to expression form (S1602)" — a Sonar mechanical sweep that collapsed the block lambda back to expression form. Worth being aware that Sonar rule S1602 (and its autofix) will reintroduce this footgun on any such lambda; the new source-policy test in #3424 guards against it.dbwiddis commentedon Jul 1, 2026
@JaynLau Since you also reported the original (#3301), here's the full story of how it came back and how we're stopping it from happening a third time.
What broke
SysFreeStringis avoidnative call, so its method handle type is(MemorySegment)void.MethodHandle.invokeExactis signature-polymorphic: its return type is inferred from the call site. In an expression-bodied lambda passed to a void-returning helper (runOrLog(...)), javac infersObjectinstead ofvoid, so the call site ((MemorySegment)Object) no longer matches the handle and throwsWrongMethodTypeException. It's caught and logged at DEBUG, so nothing crashes — but the BSTR is never freed, leaking a little memory on each WMI query.Empirically, for a
voidhandle:handle::invokeExact(method reference)() -> handle.invokeExact()(expression lambda)() -> { handle.invokeExact(); }(block lambda)Why it regressed (it was a Sonar rule, not the package move)
#3302 originally fixed this in two places by using block lambdas:
BStrFFM.freeandOle32FFM.CoUninitialize. The later FFM package move (#3356) preserved both. What re-broke it was a Sonar mechanical cleanup (#3394, rules S1602 / S1612):() -> { … }back to the expression form — exactly the shape that miscompiles a voidinvokeExact.Why only one of the two regressed
Ole32FFM.CoUninitializetakes no arguments, so after S1602 collapsed it, S1612 ("use method references") further rewrote it toCoUninitialize::invokeExact— which is the safe form (see table). It came out fine.BStrFFM.freecaptures an argument (bstr), so it can't become a no-arg method reference. S1602 collapsed it to() -> SysFreeString.invokeExact(bstr)and left it there — the broken expression form you hit.The fix and how we prevent recurrence (#3424)
BStrFFM.free.// NOSONAR (java:S1602)on that line so a future S1602 sweep can't collapse it again.VoidInvokeExactSourceTest) that scans theoshi-core-ffmsources for therunOrLog/runSilently(() -> … invokeExact)expression-lambda form (single- or multi-line) and fails the build with the offendingfile:line. Because the runtime error only fires on Windows and is swallowed, no ordinary unit test can see it — the source scan runs on every build (including non-Windows CI) and guards both call sites against reintroduction.Thanks again for the report — the stack trace made this quick to pin down.
Fix WrongMethodTypeException in BStrFFM.free void invokeExact (#3422) (…
Clear the open SonarQube findings (#3540)
Implement Display.getDevicePort() on macOS and Windows (#3678)