On Fri, 6 Nov 2026 18:45:08 GMT, yogi1967 <[email protected]> wrote:

> **Symptom:**
> On macOS, after selecting text in a Swing `JTextField` with the mouse from 
> right to left (including the first character, and releasing just past the 
> field's left edge), typing does not work normally. Each typed character 
> replaces the previous one, so the field only ever shows one character. 
> Clicking in the field clears the state.
> 
> **Cause:**
> On macOS, `nsToJavaModifiers` reads the current button state. If a 
> `MOUSE_DRAGGED` event is converted after the button is released, it has no 
> button modifier, so the mouse grab is dropped and `MOUSE_RELEASED` is 
> delivered to the wrong component. The text field never receives the 
> `MOUSE_RELEASED` event, so its `Autoscroller` continues re-applying the drag 
> selection which causes the condition where subsequently typed text appears 
> trapped in character one of the field in overtype mode.
> 
> This issue has already been addressed by JetBrains in their JDK versions:
> - JBR issue: [JBR-5762](https://youtrack.jetbrains.com/issue/JBR-5762)
> - JBR fix commit: 
> [c3cf8bddea970e9ff413b0e7ad613ed003336b21](https://github.com/JetBrains/JetBrainsRuntime/commit/c3cf8bddea970e9ff413b0e7ad613ed003336b21)
> - The current code file (refer Jbr5762Fix): 
> [CPlatformResponder.java](https://github.com/JetBrains/JetBrainsRuntime/blob/jbr25/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java)
> 
> This PR/commit applies the same fix/logic as the JBR version (without JBR's 
> on/off system property).
> 
> Testing:
> - manual tests are problematic as it depends on system and EDT load, and race 
> conditions. I was able to reproduce with manual tests, but the bug reviewer 
> was not.
> - automated `java.awt.Robot` tests don't trigger the condition
> - however, I also tested the condition in our live java application where 
> it's easier to reproduce, the error occurred after 8 attempts
> - applied this fix as patch to the same working java application and proved 
> that the issue did not occur (100 attempts), and that the fix properly caught 
> the trigger.
> - requires `noreg-hard` label added to bug report by sponsor
> - if required, I can upload the test file that intermittently works for me
> 
> Further evidence:
> - when running our live java app in debug mode within IntelliJ IDEA using JBR 
> JDK (and default parameters) the issue does not appear.
> - When running with the JBR JDK but with their 
> `-Dawt.mac.enforceMouseModifiersForMouseDragged=false` setting to disable the 
> JBR fix, the issue is reproduced.
> - I would offer that the JBR fix is already working and proven ...

Thank you for your comments. Some clarification:

I didn't just lift a commit from JetBrains. I spent many hours tracking this 
bug down in our own application, then found JetBrains had hit the same problem. 
I reviewed their change and made a similar minimal change here. I then spent a 
lot of time testing and proving the fix. 

I linked the JBR bug/fix to be open about that and to show evidence that the 
approach works. I'm not attempting to take any credit for their work. 

It's been outstanding a long time. JetBrains fixed it in JBR in June 2023 
(JBR-5762), but it never came to OpenJDK. 

The same macOS symptom has been reported to Oracle several times since July 
2023 (JDK-8311949, JDK-8325052, JDK-8370002), each closed as cannot reproduce 
or as a duplicate. I've been hitting this issue for the same timeframe.  

I've now asked JetBrains to submit their fix to OpenJDK - refer: 
https://youtrack.jetbrains.com/issue/JBR-10740

All I'm after is for this issue to be finally resolved whichever way is most 
expedient. I tried very hard to document and evidence the solution with 
thorough testing. 

I'm happy to withdraw this PR, or leave it open until JetBrains respond if 
that's useful. Your call.

Please let me know if I can provide anything further.

Thank you again for your review and response.

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

PR Comment: https://git.openjdk.org/jdk/pull/33778#issuecomment-6753428903

Reply via email to