Skip to content

Pass in project when querying flutter channel#8883

Closed
helin24 wants to merge 2 commits into
flutter:mainfrom
helin24:query-with-project
Closed

Pass in project when querying flutter channel#8883
helin24 wants to merge 2 commits into
flutter:mainfrom
helin24:query-with-project

Conversation

@helin24
Copy link
Copy Markdown
Member

@helin24 helin24 commented Apr 1, 2026

Partially fixes #8882

I was only able to reproduce the error on IDEA 2026.1, not in older versions. I verified that starting a new project with this fix in place did not show the error.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the FlutterSdk.queryFlutterChannel method to accept a Project parameter, ensuring the correct Git executable is used, and expands exception handling to include IllegalStateException. Review feedback highlights a thread-safety concern regarding the use of HashMap for cachedConfigValues when accessed from background threads, and identifies a potential lock leak in FlutterSettingsConfigurable that should be addressed by releasing the lock within a finally block.

Comment thread src/io/flutter/sdk/FlutterSdk.java
Comment thread src/io/flutter/sdk/FlutterSettingsConfigurable.java Outdated
@helin24
Copy link
Copy Markdown
Member Author

helin24 commented Apr 1, 2026

@gemini-code-assist review again

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves thread safety by switching the SDK configuration cache to a ConcurrentHashMap and enhances the queryFlutterChannel method to utilize the project context when resolving the git executable. Additionally, it ensures robust lock management in the settings configuration. Review feedback highlights a potential NullPointerException risk since ConcurrentHashMap does not permit null values, and recommends using Optional for the new method's return type to comply with the project's style guide.

private final @NotNull VirtualFile myHome;
private final @NotNull FlutterSdkVersion myVersion;
private final @NotNull Map<String, String> cachedConfigValues = new HashMap<>();
private final @NotNull Map<String, String> cachedConfigValues = new ConcurrentHashMap<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

[MUST-FIX]: The switch to ConcurrentHashMap is a good improvement for thread safety. However, unlike HashMap, ConcurrentHashMap does not allow null values. In queryFlutterChannel (line 616), the branch variable (assigned from getLocation or parseChannel) could potentially be null, which would cause a NullPointerException when calling cachedConfigValues.put("channel", branch). Please ensure that a non-null default value (e.g., "unknown") is used if the result is null.


@Nullable
@NonNls
public FlutterSdkChannel queryFlutterChannel(boolean useCachedValue, @Nullable Project project) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[NIT]: According to the Repository Style Guide (Rule 65), java.util.Optional should be used for return types that may be empty instead of returning null. Since this is a new overloaded method, consider returning Optional<FlutterSdkChannel> to align with modern Java practices in this codebase.

References
  1. Use java.util.Optional for return types that may be empty; avoid returning null. (link)

@helin24
Copy link
Copy Markdown
Member Author

helin24 commented Apr 30, 2026

I believe this is no longer needed since the project open issue was fixed.

@helin24 helin24 closed this Apr 30, 2026
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.

Exception when creating new project in IDEA 2026.1

1 participant