-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
SwingPanel
throws NPE on focus request if nothing focusable
#2512
Closed
jasonsparc opened this issue
Nov 28, 2022
· 1 comment
· Fixed by JetBrains/compose-multiplatform-core#340
Closed
SwingPanel
throws NPE on focus request if nothing focusable
#2512
jasonsparc opened this issue
Nov 28, 2022
· 1 comment
· Fixed by JetBrains/compose-multiplatform-core#340
Labels
Comments
igordmn
added a commit
to JetBrains/compose-multiplatform-core
that referenced
this issue
Dec 1, 2022
igordmn
added a commit
to JetBrains/compose-multiplatform-core
that referenced
this issue
Dec 1, 2022
igordmn
added a commit
to JetBrains/compose-multiplatform-core
that referenced
this issue
Dec 5, 2022
eymar
pushed a commit
to JetBrains/compose-multiplatform-core
that referenced
this issue
Jan 13, 2023
MatkovIvan
pushed a commit
to MatkovIvan/compose-multiplatform
that referenced
this issue
May 10, 2023
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Kotlin: 1.7.20
Compose: 1.2.1
If there's no component focusable inside a
SwingPanel
and you try to request focus to it via, e.g., tabbing, it'll crash the application.Try the following sample code,
Outcome:
Relevant stack trace:
Now, in the above sample code, set
letsSetItToFocusable = true
instead, and it won't crash anymore. That's because theSwingPanel
now has a focusable component.Digging into the source code of
SwingPanel
, I found the following lines to be problematic:https://github.com/JetBrains/androidx/blob/release/1.2.1/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/SwingPanel.desktop.kt#L190
https://github.com/JetBrains/androidx/blob/release/1.2.1/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/SwingPanel.desktop.kt#L203
The problem is, both
getFirstComponent(…)
andgetLastComponent(…)
of theFocusTraversalPolicy
interface are allowed to returnnull
, and yet the kotlin code is treating it that it won't. This was confirmed via a debugger, and also if you use the IDE to look for implementations of theFocusTraversalPolicy
interface, you will find that it may indeed return null when no swing component is focusable.Suggestion: Honor the nullability of those methods, and perhaps simply skip over the
SwingPanel
if it has no focusable components when looking for components to focus to.The text was updated successfully, but these errors were encountered: