Skip to content

Fix SwitchBase class init error: fetch AppSettingsState on-demand#1

Open
Sun-Phil-Kwon-Miro wants to merge 1 commit intoqalisander:masterfrom
Sun-Phil-Kwon-Miro:fix-error
Open

Fix SwitchBase class init error: fetch AppSettingsState on-demand#1
Sun-Phil-Kwon-Miro wants to merge 1 commit intoqalisander:masterfrom
Sun-Phil-Kwon-Miro:fix-error

Conversation

@Sun-Phil-Kwon-Miro
Copy link
Copy Markdown

Problem

SwitchBase had a static field that eagerly called AppSettingsState.getInstance() during class initialization:

private static final AppSettingsState settings = AppSettingsState.getInstance();

This runs inside <clinit> — when IntelliJ first loads the action class (e.g. on a keymap lookup). At that point the service container is not yet ready, causing:

java.lang.Throwable: switcher.intellij.actions.SwitchBase <clinit> requests
switcher.intellij.settings.AppSettingsState instance.
Class initialization must not depend on services.
Consider using instance of the service on-demand instead.

The error surfaced every time a key was pressed, since IntelliJ tries to resolve the action for keymap matching.

Fix

Replace the static field with a private static accessor method that fetches the service on-demand:

private static AppSettingsState settings() { return AppSettingsState.getInstance(); }

The service is now only retrieved when an action is actually executed, at which point the container is fully initialized. All call sites updated from settings. to settings().

Test plan

  • Build and run the plugin in a sandbox IDE instance
  • Verify no <clinit> error appears in the IDE log on startup or key press
  • Verify switch actions (left/right/top/bottom panels) still work correctly
  • Verify settings (rememberLastOpened, focusOnSwitched, etc.) are respected

🤖 Generated with Claude Code

AppSettingsState.getInstance() was called in a static field initializer,
which runs during <clinit> before IntelliJ's service container is ready.
Replace the static field with an on-demand accessor method so the service
is only fetched at action execution time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Sun-Phil-Kwon-Miro
Copy link
Copy Markdown
Author

@qalisander

@Sun-Phil-Kwon-Miro
Copy link
Copy Markdown
Author

Any news on this?

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.

1 participant