43
43
*/
44
44
public class FlutterConsoleFilter implements Filter {
45
45
private static class OpenExternalFileHyperlink implements HyperlinkInfo {
46
- private final String myPath ;
46
+ private final @ NotNull String myPath ;
47
47
48
- OpenExternalFileHyperlink (VirtualFile file ) {
48
+ OpenExternalFileHyperlink (@ NotNull VirtualFile file ) {
49
49
myPath = file .getPath ();
50
50
}
51
51
@@ -87,12 +87,13 @@ public VirtualFile fileAtPath(@NotNull String pathPart) {
87
87
88
88
// We require the pathPart reference to be a file reference, otherwise we'd match things like
89
89
// "Build: Running build completed, took 191ms".
90
- if (pathPart .indexOf ('.' ) == -1 ) {
90
+ if (pathPart == null || pathPart .indexOf ('.' ) == -1 ) {
91
91
return null ;
92
92
}
93
93
94
94
final VirtualFile [] roots = OpenApiUtils .getContentRoots (module );
95
95
for (VirtualFile root : roots ) {
96
+ if (root == null ) continue ;
96
97
if (!pathPart .isEmpty ()) {
97
98
final String baseDirPath = root .getPath ();
98
99
final String path = baseDirPath + "/" + pathPart ;
@@ -112,14 +113,14 @@ public VirtualFile fileAtPath(@NotNull String pathPart) {
112
113
return null ;
113
114
}
114
115
115
- private static VirtualFile findFile (final String path ) {
116
+ private static @ Nullable VirtualFile findFile (final @ NotNull String path ) {
116
117
final VirtualFile file = LocalFileSystem .getInstance ().findFileByPath (path );
117
118
return file != null && file .exists () ? file : null ;
118
119
}
119
120
120
121
@ Override
121
122
@ Nullable
122
- public Result applyFilter (final String line , final int entireLength ) {
123
+ public Result applyFilter (final @ NotNull String line , final int entireLength ) {
123
124
if (line .startsWith ("Run \" flutter doctor\" for information about installing additional components." )) {
124
125
return getFlutterDoctorResult (line , entireLength - line .length ());
125
126
}
@@ -141,10 +142,12 @@ public Result applyFilter(final String line, final int entireLength) {
141
142
final String [] parts = pathPart .split (" " );
142
143
if (parts .length > 1 ) {
143
144
pathPart = parts [1 ];
144
- file = fileAtPath (pathPart );
145
- if (file != null ) {
146
- lineStart = entireLength - line .length () + line .indexOf (pathPart );
147
- highlightLength = pathPart .length ();
145
+ if (pathPart != null ) {
146
+ file = fileAtPath (pathPart );
147
+ if (file != null ) {
148
+ lineStart = entireLength - line .length () + line .indexOf (pathPart );
149
+ highlightLength = pathPart .length ();
150
+ }
148
151
}
149
152
}
150
153
}
@@ -155,12 +158,13 @@ public Result applyFilter(final String line, final int entireLength) {
155
158
final String [] parts = pathPart .split (" " );
156
159
for (String part : parts ) {
157
160
// "(lib/main.dart:49)"
158
- if (part .startsWith ("(" ) && part .endsWith (")" )) {
161
+ if (part != null && part .startsWith ("(" ) && part .endsWith (")" )) {
159
162
part = part .substring (1 , part .length () - 1 );
160
163
final String [] split = part .split (":" );
161
164
if (split .length == 2 ) {
162
165
try {
163
166
// Reconcile line number indexing.
167
+ //noinspection DataFlowIssue
164
168
lineNumber = Math .max (0 , Integer .parseInt (split [1 ]) - 1 );
165
169
}
166
170
catch (NumberFormatException e ) {
@@ -175,6 +179,7 @@ else if (split.length == 4 && Objects.equals(split[0], "file")) {
175
179
// part = file:///Users/user/AndroidStudioProjects/flutter_app/test/widget_test.dart:23:18
176
180
try {
177
181
// Reconcile line number indexing.
182
+ //noinspection DataFlowIssue
178
183
lineNumber = Math .max (0 , Integer .parseInt (split [2 ]) - 1 );
179
184
}
180
185
catch (NumberFormatException e ) {
@@ -200,13 +205,15 @@ else if (split.length == 4 && Objects.equals(split[0], "file")) {
200
205
if (found ) {
201
206
final String filePathExpr = "((?:[^/]*/)*)(.*)" ;
202
207
final Pattern pathPattern = Pattern .compile (filePathExpr );
208
+ //noinspection DataFlowIssue
203
209
final Matcher pathMatcher = pathPattern .matcher (matcher .group (1 ));
204
210
if (pathMatcher .find ()) {
205
211
final String path = pathMatcher .group (1 ) + pathMatcher .group (2 );
206
212
file = fileAtPath (path );
207
213
if (file == null ) {
208
214
return null ;
209
215
}
216
+ //noinspection DataFlowIssue
210
217
lineNumber = Integer .parseInt (matcher .group (2 ));
211
218
lineStart = entireLength - line .length ();
212
219
highlightLength = path .length ();
@@ -236,9 +243,11 @@ else if (split.length == 4 && Objects.equals(split[0], "file")) {
236
243
return null ;
237
244
}
238
245
239
- private String findRelativePath (String threeSlashFileName ) {
246
+ private @ Nullable String findRelativePath (@ Nullable String threeSlashFileName ) {
247
+ if (threeSlashFileName == null ) return null ;
240
248
final VirtualFile [] roots = OpenApiUtils .getContentRoots (module );
241
249
for (VirtualFile root : roots ) {
250
+ if (root == null ) continue ;
242
251
final String path = root .getPath ();
243
252
int index = threeSlashFileName .indexOf (path );
244
253
if (index > 0 ) {
@@ -249,7 +258,7 @@ private String findRelativePath(String threeSlashFileName) {
249
258
return null ;
250
259
}
251
260
252
- private static Result getFlutterDoctorResult (final String line , final int lineStart ) {
261
+ private static @ NotNull Result getFlutterDoctorResult (final @ NotNull String line , final int lineStart ) {
253
262
final int commandStart = line .indexOf ('"' ) + 1 ;
254
263
final int startOffset = lineStart + commandStart ;
255
264
final int commandLength = "flutter doctor" .length ();
0 commit comments