Skip to content

Commit 6b34f28

Browse files
authored
[CQ] fix nullability problems for flutter/inspections (#8303)
Fix nullability problems in `src/io/flutter/inspections/`. See #8291. If we pursue #8292, we could mark `src/io/flutter/inspections/` 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 4a5eb90 commit 6b34f28

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

flutter-idea/src/io/flutter/inspections/FlutterDependencyInspection.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull fi
5454
// If the project should use bazel instead of pub, don't surface this warning.
5555
if (WorkspaceCache.getInstance(project).isBazel()) return null;
5656

57-
if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) return null;
57+
58+
var projectRootManager = ProjectRootManager.getInstance(project);
59+
if (projectRootManager == null) return null;
60+
61+
if (!projectRootManager.getFileIndex().isInContent(file)) return null;
5862

5963
final Module module = ModuleUtilCore.findModuleForFile(file, project);
6064
if (!FlutterModuleUtils.isFlutterModule(module)) return null;
@@ -83,6 +87,7 @@ private ProblemDescriptor[] createProblemDescriptors(@NotNull final InspectionMa
8387
@NotNull final PsiFile psiFile,
8488
@NotNull final PubRoot root,
8589
@NotNull final String errorMessage) {
90+
//noinspection DataFlowIssue
8691
final LocalQuickFix[] fixes = new LocalQuickFix[]{
8792
new PackageUpdateFix(FlutterBundle.message("get.dependencies"), FlutterSdk::startPubGet),
8893
new PackageUpdateFix(FlutterBundle.message("upgrade.dependencies"), FlutterSdk::startPubUpgrade),
@@ -133,7 +138,7 @@ public void applyFix(@NotNull final Project project, @NotNull final PsiFile psiF
133138
// TODO(skybrian) analytics?
134139
mySdkAction.run(sdk, root, project);
135140

136-
DaemonCodeAnalyzer.getInstance(project).restart(psiFile);
141+
restartCodeAnalyzer(project, psiFile);
137142
}
138143
}
139144

@@ -166,7 +171,17 @@ public boolean startInWriteAction() {
166171
@Override
167172
public void applyFix(@NotNull final Project project, @NotNull final PsiFile psiFile, @Nullable final Editor editor) {
168173
myIgnoredPubspecPaths.add(myPubspecPath);
169-
DaemonCodeAnalyzer.getInstance(project).restart(psiFile);
174+
175+
restartCodeAnalyzer(project, psiFile);
176+
}
177+
}
178+
179+
private static void restartCodeAnalyzer(@NotNull final Project project, @NotNull final PsiFile psiFile) {
180+
var codeAnalyzer = DaemonCodeAnalyzer.getInstance(project);
181+
if (codeAnalyzer != null) {
182+
codeAnalyzer.restart(psiFile);
170183
}
171184
}
172185
}
186+
187+

0 commit comments

Comments
 (0)