Skip to content

Commit bb67f19

Browse files
authored
[fix] allow nullable fileOrDir for client compatibility (#8409)
The `flutter_enhancement_suite` uses `PubRoot.forDescendant` but does not ensure null safety. Since the plugin is not being actively maintained (but still adding value), this adjusts the API to be defensive. Fixes #8399 --- <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 f9d7f33 commit bb67f19

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/io/flutter/pub/PubRoot.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ public static PubRoot forPsiFile(@NotNull PsiFile psiFile) {
118118
* Based on the filesystem cache; doesn't refresh anything.
119119
*/
120120
@Nullable
121-
public static PubRoot forDescendant(@NotNull VirtualFile fileOrDir, @NotNull Project project) {
121+
public static PubRoot forDescendant(@Nullable VirtualFile fileOrDir, @NotNull Project project) {
122+
// To be compatible w/ `flutter_enhancement_suite`, we allow a null `fileOrDir`.
123+
// https://github.com/flutter/flutter-intellij/issues/8399
124+
if (fileOrDir == null) return null;
122125
ProjectRootManager manager = ProjectRootManager.getInstance(project);
123126
if (manager == null) return null;
127+
124128
final ProjectFileIndex index = manager.getFileIndex();
125129
return OpenApiUtils.safeRunReadAction(() -> {
126130
final VirtualFile root = index.getContentRootForFile(fileOrDir);

0 commit comments

Comments
 (0)