Skip to content

Commit 9c7fa7e

Browse files
authored
[CQ] fix nullability problems for flutter/bazel (#8296)
Fix nullability problems in `src/io/flutter/bazel/`. See #8291. If we pursue #8292, we could mark `src/io/flutter/bazel/` as null-"clean". --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](#8098)). </details>
1 parent dd99416 commit 9c7fa7e

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

flutter-idea/src/io/flutter/bazel/PluginConfig.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ public static PluginConfig load(@NotNull VirtualFile file) {
113113
final Computable<PluginConfig> readAction = () -> {
114114
try (
115115
// Create the input stream in a try-with-resources statement. This will automatically close the stream
116-
// in an implicit finally section; this addresses a file handle leak issue we had on MacOS.
116+
// in an implicit finally section; this addresses a file handle leak issue we had on macOS.
117117
final InputStreamReader input = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)
118118
) {
119119
final Fields fields = GSON.fromJson(input, Fields.class);
120+
assert fields != null;
120121
return new PluginConfig(fields);
121122
}
122123
catch (FileNotFoundException e) {
@@ -142,7 +143,7 @@ public static PluginConfig load(@NotNull VirtualFile file) {
142143
}
143144

144145
@VisibleForTesting
145-
public static PluginConfig forTest(
146+
public static @NotNull PluginConfig forTest(
146147
@Nullable String daemonScript,
147148
@Nullable String devToolsScript,
148149
@Nullable String doctorScript,
@@ -181,86 +182,86 @@ private static class Fields {
181182
* The script to run to start 'flutter daemon'.
182183
*/
183184
@SerializedName("daemonScript")
184-
private String daemonScript;
185+
private @Nullable String daemonScript;
185186

186187
@SerializedName("devToolsScript")
187-
private String devToolsScript;
188+
private @Nullable String devToolsScript;
188189

189190
/**
190191
* The script to run to start 'flutter doctor'.
191192
*/
192193
@SerializedName("doctorScript")
193-
private String doctorScript;
194+
private @Nullable String doctorScript;
194195

195196
/**
196197
* The script to run to start 'flutter test'
197198
*/
198199
@SerializedName("testScript")
199-
private String testScript;
200+
private @Nullable String testScript;
200201

201202
/**
202203
* The script to run to start 'flutter run'
203204
*/
204205
@SerializedName("runScript")
205-
private String runScript;
206+
private @Nullable String runScript;
206207

207208
/**
208209
* The script to run to start 'flutter sync'
209210
*/
210211
@SerializedName("syncScript")
211-
private String syncScript;
212+
private @Nullable String syncScript;
212213

213214
@SerializedName("toolsScript")
214-
private String toolsScript;
215+
private @Nullable String toolsScript;
215216

216217
/**
217218
* The directory containing the SDK tools.
218219
*/
219220
@SerializedName("sdkHome")
220-
private String sdkHome;
221+
private @Nullable String sdkHome;
221222

222223
/**
223224
* The file containing the Flutter version.
224225
*/
225226
@SerializedName("requiredIJPluginID")
226-
private String requiredIJPluginID;
227+
private @Nullable String requiredIJPluginID;
227228

228229
/**
229230
* The file containing the message to install the required IJ Plugin.
230231
*/
231232
@SerializedName("requiredIJPluginMessage")
232-
private String requiredIJPluginMessage;
233+
private @Nullable String requiredIJPluginMessage;
233234

234235
/**
235236
* The prefix that indicates a configuration warning message.
236237
*/
237238
@SerializedName("configWarningPrefix")
238-
private String configWarningPrefix;
239+
private @Nullable String configWarningPrefix;
239240

240241
/**
241242
* The prefix that indicates a message about iOS run being updated.
242243
*/
243244
@SerializedName("updatedIosRunMessage")
244-
private String updatedIosRunMessage;
245+
private @Nullable String updatedIosRunMessage;
245246

246247
Fields() {
247248
}
248249

249250
/**
250251
* Convenience constructor that takes all parameters.
251252
*/
252-
Fields(String daemonScript,
253-
String devToolsScript,
254-
String doctorScript,
255-
String testScript,
256-
String runScript,
257-
String syncScript,
258-
String toolsScript,
259-
String sdkHome,
260-
String requiredIJPluginID,
261-
String requiredIJPluginMessage,
262-
String configWarningPrefix,
263-
String updatedIosRunMessage) {
253+
Fields(@Nullable String daemonScript,
254+
@Nullable String devToolsScript,
255+
@Nullable String doctorScript,
256+
@Nullable String testScript,
257+
@Nullable String runScript,
258+
@Nullable String syncScript,
259+
@Nullable String toolsScript,
260+
@Nullable String sdkHome,
261+
@Nullable String requiredIJPluginID,
262+
@Nullable String requiredIJPluginMessage,
263+
@Nullable String configWarningPrefix,
264+
@Nullable String updatedIosRunMessage) {
264265
this.daemonScript = daemonScript;
265266
this.devToolsScript = devToolsScript;
266267
this.doctorScript = doctorScript;
@@ -298,6 +299,6 @@ public int hashCode() {
298299
}
299300
}
300301

301-
private static final Gson GSON = new Gson();
302+
private static final @NotNull Gson GSON = new Gson();
302303
private static final @NotNull Logger LOG = Logger.getInstance(PluginConfig.class);
303304
}

flutter-idea/src/io/flutter/bazel/Workspace.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ static Workspace loadUncached(@NotNull Project project) {
274274
if (workspaceFile == null) return null;
275275

276276
final VirtualFile root = workspaceFile.getParent();
277+
if (root == null) return null;
277278
final String readonlyPath = "../READONLY/" + root.getName();
278279
final VirtualFile readonlyRoot = root.findFileByRelativePath(readonlyPath);
279280
VirtualFile configFile = root.findFileByRelativePath(PLUGIN_CONFIG_PATH);
@@ -313,7 +314,7 @@ static Workspace loadUncached(@NotNull Project project) {
313314
}
314315

315316
@VisibleForTesting
316-
public static Workspace forTest(VirtualFile workspaceRoot, PluginConfig pluginConfig) {
317+
public static Workspace forTest(@NotNull VirtualFile workspaceRoot, @NotNull PluginConfig pluginConfig) {
317318
return new Workspace(
318319
workspaceRoot,
319320
pluginConfig,
@@ -339,7 +340,9 @@ public static Workspace forTest(VirtualFile workspaceRoot, PluginConfig pluginCo
339340
* @param relativeScriptPath the relative path to the desired script inside of the workspace.
340341
* @return the script's path relative to the workspace, or null if it was not found.
341342
*/
342-
private static String getScriptFromPath(@NotNull VirtualFile root, @NotNull String readonlyPath, @Nullable String relativeScriptPath) {
343+
private static @Nullable String getScriptFromPath(@NotNull VirtualFile root,
344+
@NotNull String readonlyPath,
345+
@Nullable String relativeScriptPath) {
343346
if (relativeScriptPath == null) {
344347
return null;
345348
}
@@ -363,8 +366,12 @@ private static String getScriptFromPath(@NotNull VirtualFile root, @NotNull Stri
363366
@Nullable
364367
private static VirtualFile findWorkspaceFile(@NotNull Project p) {
365368
final Computable<VirtualFile> readAction = () -> {
369+
ProjectRootManager rootManager = ProjectRootManager.getInstance(p);
370+
if (rootManager == null) return null;
371+
366372
final Map<String, VirtualFile> candidates = new HashMap<>();
367-
for (VirtualFile contentRoot : ProjectRootManager.getInstance(p).getContentRoots()) {
373+
for (VirtualFile contentRoot : rootManager.getContentRoots()) {
374+
if (contentRoot == null) continue;
368375
final VirtualFile wf = findContainingWorkspaceFile(contentRoot);
369376
if (wf != null) {
370377
candidates.put(wf.getPath(), wf);
@@ -404,7 +411,7 @@ private static VirtualFile findContainingWorkspaceFile(@NotNull VirtualFile dir)
404411
return null;
405412
}
406413

407-
public String convertPath(String path) {
414+
public String convertPath(@NotNull String path) {
408415
if (path.startsWith(Workspace.BAZEL_URI_SCHEME)) {
409416
return getRoot().getPath() + path.substring(Workspace.BAZEL_URI_SCHEME.length());
410417
}

0 commit comments

Comments
 (0)