Skip to content

[CQ] fix nullability problems for flutter/bazel #8296

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

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions flutter-idea/src/io/flutter/bazel/PluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ public static PluginConfig load(@NotNull VirtualFile file) {
final Computable<PluginConfig> readAction = () -> {
try (
// Create the input stream in a try-with-resources statement. This will automatically close the stream
// in an implicit finally section; this addresses a file handle leak issue we had on MacOS.
// in an implicit finally section; this addresses a file handle leak issue we had on macOS.
final InputStreamReader input = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)
) {
final Fields fields = GSON.fromJson(input, Fields.class);
assert fields != null;
return new PluginConfig(fields);
}
catch (FileNotFoundException e) {
Expand All @@ -142,7 +143,7 @@ public static PluginConfig load(@NotNull VirtualFile file) {
}

@VisibleForTesting
public static PluginConfig forTest(
public static @NotNull PluginConfig forTest(
@Nullable String daemonScript,
@Nullable String devToolsScript,
@Nullable String doctorScript,
Expand Down Expand Up @@ -181,86 +182,86 @@ private static class Fields {
* The script to run to start 'flutter daemon'.
*/
@SerializedName("daemonScript")
private String daemonScript;
private @Nullable String daemonScript;

@SerializedName("devToolsScript")
private String devToolsScript;
private @Nullable String devToolsScript;

/**
* The script to run to start 'flutter doctor'.
*/
@SerializedName("doctorScript")
private String doctorScript;
private @Nullable String doctorScript;

/**
* The script to run to start 'flutter test'
*/
@SerializedName("testScript")
private String testScript;
private @Nullable String testScript;

/**
* The script to run to start 'flutter run'
*/
@SerializedName("runScript")
private String runScript;
private @Nullable String runScript;

/**
* The script to run to start 'flutter sync'
*/
@SerializedName("syncScript")
private String syncScript;
private @Nullable String syncScript;

@SerializedName("toolsScript")
private String toolsScript;
private @Nullable String toolsScript;

/**
* The directory containing the SDK tools.
*/
@SerializedName("sdkHome")
private String sdkHome;
private @Nullable String sdkHome;

/**
* The file containing the Flutter version.
*/
@SerializedName("requiredIJPluginID")
private String requiredIJPluginID;
private @Nullable String requiredIJPluginID;

/**
* The file containing the message to install the required IJ Plugin.
*/
@SerializedName("requiredIJPluginMessage")
private String requiredIJPluginMessage;
private @Nullable String requiredIJPluginMessage;

/**
* The prefix that indicates a configuration warning message.
*/
@SerializedName("configWarningPrefix")
private String configWarningPrefix;
private @Nullable String configWarningPrefix;

/**
* The prefix that indicates a message about iOS run being updated.
*/
@SerializedName("updatedIosRunMessage")
private String updatedIosRunMessage;
private @Nullable String updatedIosRunMessage;

Fields() {
}

/**
* Convenience constructor that takes all parameters.
*/
Fields(String daemonScript,
String devToolsScript,
String doctorScript,
String testScript,
String runScript,
String syncScript,
String toolsScript,
String sdkHome,
String requiredIJPluginID,
String requiredIJPluginMessage,
String configWarningPrefix,
String updatedIosRunMessage) {
Fields(@Nullable String daemonScript,
@Nullable String devToolsScript,
@Nullable String doctorScript,
@Nullable String testScript,
@Nullable String runScript,
@Nullable String syncScript,
@Nullable String toolsScript,
@Nullable String sdkHome,
@Nullable String requiredIJPluginID,
@Nullable String requiredIJPluginMessage,
@Nullable String configWarningPrefix,
@Nullable String updatedIosRunMessage) {
this.daemonScript = daemonScript;
this.devToolsScript = devToolsScript;
this.doctorScript = doctorScript;
Expand Down Expand Up @@ -298,6 +299,6 @@ public int hashCode() {
}
}

private static final Gson GSON = new Gson();
private static final @NotNull Gson GSON = new Gson();
private static final @NotNull Logger LOG = Logger.getInstance(PluginConfig.class);
}
15 changes: 11 additions & 4 deletions flutter-idea/src/io/flutter/bazel/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ static Workspace loadUncached(@NotNull Project project) {
if (workspaceFile == null) return null;

final VirtualFile root = workspaceFile.getParent();
if (root == null) return null;
final String readonlyPath = "../READONLY/" + root.getName();
final VirtualFile readonlyRoot = root.findFileByRelativePath(readonlyPath);
VirtualFile configFile = root.findFileByRelativePath(PLUGIN_CONFIG_PATH);
Expand Down Expand Up @@ -313,7 +314,7 @@ static Workspace loadUncached(@NotNull Project project) {
}

@VisibleForTesting
public static Workspace forTest(VirtualFile workspaceRoot, PluginConfig pluginConfig) {
public static Workspace forTest(@NotNull VirtualFile workspaceRoot, @NotNull PluginConfig pluginConfig) {
return new Workspace(
workspaceRoot,
pluginConfig,
Expand All @@ -339,7 +340,9 @@ public static Workspace forTest(VirtualFile workspaceRoot, PluginConfig pluginCo
* @param relativeScriptPath the relative path to the desired script inside of the workspace.
* @return the script's path relative to the workspace, or null if it was not found.
*/
private static String getScriptFromPath(@NotNull VirtualFile root, @NotNull String readonlyPath, @Nullable String relativeScriptPath) {
private static @Nullable String getScriptFromPath(@NotNull VirtualFile root,
@NotNull String readonlyPath,
@Nullable String relativeScriptPath) {
if (relativeScriptPath == null) {
return null;
}
Expand All @@ -363,8 +366,12 @@ private static String getScriptFromPath(@NotNull VirtualFile root, @NotNull Stri
@Nullable
private static VirtualFile findWorkspaceFile(@NotNull Project p) {
final Computable<VirtualFile> readAction = () -> {
ProjectRootManager rootManager = ProjectRootManager.getInstance(p);
if (rootManager == null) return null;

final Map<String, VirtualFile> candidates = new HashMap<>();
for (VirtualFile contentRoot : ProjectRootManager.getInstance(p).getContentRoots()) {
for (VirtualFile contentRoot : rootManager.getContentRoots()) {
if (contentRoot == null) continue;
final VirtualFile wf = findContainingWorkspaceFile(contentRoot);
if (wf != null) {
candidates.put(wf.getPath(), wf);
Expand Down Expand Up @@ -404,7 +411,7 @@ private static VirtualFile findContainingWorkspaceFile(@NotNull VirtualFile dir)
return null;
}

public String convertPath(String path) {
public String convertPath(@NotNull String path) {
if (path.startsWith(Workspace.BAZEL_URI_SCHEME)) {
return getRoot().getPath() + path.substring(Workspace.BAZEL_URI_SCHEME.length());
}
Expand Down