Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🐛 Fix DeviceSelectorAction NoSuchElementException in the toolbar layout #8515

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

Open
AlexV525 wants to merge 3 commits into main
base: main
Choose a base branch
Loading
from copilot/fix-8494

Conversation

Copy link
Member

@AlexV525 AlexV525 commented Sep 4, 2025

(originally #8496)

This PR fixes a NoSuchElementException that occurs in the DeviceSelectorAction when IntelliJ's toolbar layout system tries to calculate component widths.

Problem

The error manifested as:

java.util.NoSuchElementException: Key io.flutter.actions.DeviceSelectorAction1ドル[...] is missing in the map.
	at kotlin.collections.MapsKt__MapWithDefaultKt.getOrImplicitDefaultNullable(MapWithDefault.kt:24)
	at kotlin.collections.MapsKt__MapsKt.getValue(Maps.kt:369)
	at com.intellij.openapi.actionSystem.toolbarLayout.CompressingLayoutStrategyKt.calculateComponentWidths(CompressingLayoutStrategy.kt:200)

Root Cause

The getPreferredSize() method in the anonymous JButton class was being called by IntelliJ's layout system before the client properties (ICON_LABEL_KEY, TEXT_LABEL_KEY, ARROW_LABEL_KEY) were set during component initialization. This caused the layout system to fail when trying to register the component in its internal maps because:

  1. The method accessed null client properties without proper fallback handling
  2. Used unsafe Objects.requireNonNull(fm) calls that could throw exceptions
  3. The layout system couldn't determine proper component dimensions during initialization

Solution

Enhanced the getPreferredSize() method with defensive programming:

  • Added fallback logic: When client properties are null (during initialization), use the same default icons and text that would normally be used
  • Safe null checking: Replaced Objects.requireNonNull(fm) with proper null checks
  • Reasonable defaults: Provide sensible sizing estimates using FlutterIcons.Mobile, chevron down icon, and "No device selected" text width
// Before: Unsafe access
width += Objects.requireNonNull(fm).stringWidth(text);
// After: Defensive with fallback
if (fm != null) {
 width += fm.stringWidth(text);
 height = Math.max(height, fm.getHeight());
}

Impact

  • Eliminates NoSuchElementException during toolbar initialization
  • Maintains exact same functionality once component is fully initialized
  • No performance impact - fallback logic only runs during the brief initialization phase
  • More robust component that gracefully handles IntelliJ's layout timing

Fixes #8494.

@AlexV525 AlexV525 self-assigned this Sep 4, 2025
@AlexV525 AlexV525 requested a review from pq September 4, 2025 07:06
@AlexV525 AlexV525 marked this pull request as ready for review September 4, 2025 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@pq pq Awaiting requested review from pq

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

DeviceSelectorAction: NoSuchElementException
1 participant

AltStyle によって変換されたページ (->オリジナル) /