On Sun, 4 May 2025 20:25:02 GMT, Chen Liang <[email protected]> wrote:

>> src/java.base/share/classes/java/lang/foreign/Linker.java line 866:
>> 
>>> 864:                     .map(CapturableState::forName)
>>> 865:                     .mapToInt(state -> 1 << state.ordinal())
>>> 866:                     .sum();
>> 
>> Using `sum` means the result will be incorrect if `capturedState` contains a 
>> valid name multiple times:
>> 
>> var option = 
>> (LinkerOptions.CaptureCallState)Linker.Option.captureCallState("WSAGetLastError",
>>  "WSAGetLastError");
>> 
>> // will print [ERRNO] on Windows
>> System.out.println(option.saved());
>> 
>> 
>> option = 
>> (LinkerOptions.CaptureCallState)Linker.Option.captureCallState("errno", 
>> "errno");
>> 
>> // will throw IndexOutOfBoundsException on all platforms
>> option.saved();
>
> Hmm, I intentionally checked `toSet` does not reject duplicates but forgot 
> about this part. Anyways this stream code is problematic; will fix this in a 
> patch that removes this stream code wholesale.

I created an issue to revisit CapturableState 
https://bugs.openjdk.org/browse/JDK-8356126 and will fix these problem with new 
unit test ensuring the toString message and nonexistent/duplicate behaviors, 
also removing redundant stream usage.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24742#discussion_r2072721337

Reply via email to