-
-
Notifications
You must be signed in to change notification settings - Fork 443
jvm: fix macOS accessibility crash and update Compose to 1.10.3 #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
composeApp/src/jvmMain/kotlin/zed/rainxch/githubstore/A11yCrashGuard.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package zed.rainxch.githubstore | ||
|
|
||
| import java.awt.AWTEvent | ||
| import java.awt.EventQueue | ||
| import java.awt.Toolkit | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
|
|
||
| /** | ||
| * Workaround for a Compose Multiplatform 1.10.x NPE on macOS where the native | ||
| * AX bridge (`sun.lwawt.macosx.CAccessible$AXChangeNotifier`) queries a | ||
| * Compose semantic node that has already been removed by Compose's own | ||
| * accessibility sync loop. The stack trace fingerprint is: | ||
| * | ||
| * androidx.compose.ui.platform.a11y.SemanticsOwnerAccessibility.accessibleParentOf | ||
| * -> sun.lwawt.macosx.CAccessible$AXChangeNotifier.propertyChange | ||
| * | ||
| * The uncaught exception poisons the AWT EventDispatchThread and the app | ||
| * appears to freeze/crash on click. Installing a filtering [EventQueue] | ||
| * swallows only that specific NPE so the EDT keeps draining events. | ||
| * Trade-off: macOS VoiceOver may miss updates on those removed nodes. | ||
| * Remove once the upstream fix lands (track against Compose MP 1.11+). | ||
| * | ||
| * See [GitHub-Store#330](https://github.com/OpenHub-Store/GitHub-Store/issues/330). | ||
| */ | ||
| object A11yCrashGuard { | ||
| fun install() { | ||
| val osName = System.getProperty("os.name")?.lowercase().orEmpty() | ||
| if (!osName.contains("mac")) return | ||
| Toolkit.getDefaultToolkit().systemEventQueue.push(FilteringEventQueue()) | ||
| } | ||
|
|
||
| private class FilteringEventQueue : EventQueue() { | ||
| private val warned = AtomicBoolean(false) | ||
|
|
||
| override fun dispatchEvent(event: AWTEvent) { | ||
| try { | ||
| super.dispatchEvent(event) | ||
| } catch (npe: NullPointerException) { | ||
| if (isComposeA11yNpe(npe)) { | ||
| if (warned.compareAndSet(false, true)) { | ||
| System.err.println( | ||
| "[A11yCrashGuard] Suppressed Compose a11y NPE on macOS " + | ||
| "(known issue, see GitHub-Store#330). Further occurrences silenced.", | ||
| ) | ||
| } | ||
| return | ||
| } | ||
| throw npe | ||
| } | ||
| } | ||
|
|
||
| private fun isComposeA11yNpe(throwable: Throwable): Boolean { | ||
| var current: Throwable? = throwable | ||
| while (current != null) { | ||
| if (current.stackTrace.any { frame -> | ||
| frame.className.startsWith("androidx.compose.ui.platform.a11y") | ||
| } | ||
| ) { | ||
| return true | ||
| } | ||
| current = current.cause | ||
| } | ||
| return false | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
install()is not idempotent.Every call pushes another
FilteringEventQueueon top of the current system event queue. If startup ever invokes this twice (tests, hot-reload, restart paths), you'll stack filtering queues and each event will traverse multipledispatchEventframes. Consider guarding with anAtomicBooleanso subsequent calls are no-ops.Proposed fix
object A11yCrashGuard { + private val installed = java.util.concurrent.atomic.AtomicBoolean(false) + fun install() { val osName = System.getProperty("os.name")?.lowercase().orEmpty() if (!osName.contains("mac")) return + if (!installed.compareAndSet(false, true)) return Toolkit.getDefaultToolkit().systemEventQueue.push(FilteringEventQueue()) }🤖 Prompt for AI Agents