Skip to content

Fix Resources$NotFoundException crash when a subtype name string is missing - #899

Open
MiMoHo wants to merge 1 commit into
openboard-team:masterfrom
MiMoHo:fix/subtype-name-crash
Open

MiMoHo wants to merge 1 commit into
openboard-team:masterfrom
MiMoHo:fix/subtype-name-crash

Conversation

@MiMoHo

@MiMoHo MiMoHo commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Selecting certain subtypes crashes the keyboard with Resources$NotFoundException: String resource ID #0x0 thrown from SubtypeLocaleUtils (#175).

Resources.getIdentifier() returns 0 when a subtype_* string does not exist for a locale listed in subtype_locale_exception_keys, subtype_locale_displayed_in_root_locale or predefined_layouts. Those zeros were stored unchecked in the name-id maps, and the display-name lookup later calls res.getString(0), which throws.

Fix

  • Skip registering resource ids that resolved to 0, so the existing fallbacks kick in (locale display name, UNKNOWN_KEYBOARD_LAYOUT).
  • Keep sExceptionalLocaleToNameIdsMap and sExceptionalLocaleToWithLayoutNameIdsMap in sync (a locale is only "exceptional" when both strings exist), because isExceptionalLocale() checks one map while getSubtypeNameId() reads the other — an asymmetric skip would trade the crash for an NPE.
  • Guard the exceptional-name lookup against a stored 0 as a second line of defence.

Testing

Builds with the stock toolchain (AGP 7.0.4/JDK 11); keyboard smoke-tested on an Android 15 emulator (typing, suggestions, subtype switching). The crash itself needs a subtype whose name string is missing, which none of the bundled subtypes currently triggers — the fix makes the code robust against that class of mismatch (as reported from third-party/derived builds in #175).

Fixes #175

🤖 Generated with Claude Code

…eam#175)

Resources.getIdentifier() returns 0 when a subtype_* string does not
exist for a locale listed in subtype_locale_exception_keys,
subtype_locale_displayed_in_root_locale or predefined_layouts. These 0
values were stored unchecked in the name-id maps, and
getSubtypeLocaleDisplayNameInternal() later called getString(0), which
throws Resources$NotFoundException: 'String resource ID #0x0' and
crashes the keyboard when such a subtype is selected.

Skip registering missing resources so the existing fallbacks kick in
(locale display name / UNKNOWN_KEYBOARD_LAYOUT), keep the two
exceptional-locale maps in sync because isExceptionalLocale() checks
one while getSubtypeNameId() reads the other, and guard the
exceptional-name lookup against a stored 0 as a second line of defence.

Fixes openboard-team#175

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@MiMoHo
MiMoHo force-pushed the fix/subtype-name-crash branch from 4e4894b to 3019766 Compare September 9, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resources$NotFoundException

1 participant