Skip to content

Commit bbe6f23

Browse files
DanTupCommit Queue
authored and
Commit Queue
committed
[analyzer] Don't crash on certain types of invalid data in analysis_options linter config
Fixes #56577 Fixes #55594 Change-Id: I1e69937cd104e8101a7f87b7c9b8ce26b914b3a0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382605 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent ddab694 commit bbe6f23

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

pkg/analyzer/lib/src/lint/config.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class _LintConfig implements LintConfig {
9090
}
9191

9292
String? asString(Object scalar) {
93-
var value = scalar is YamlScalar ? scalar.valueOrThrow : scalar;
93+
var value = scalar is YamlScalar ? scalar.value : scalar;
9494
if (value is String) {
9595
return value;
9696
}
@@ -158,7 +158,7 @@ class _LintConfig implements LintConfig {
158158
var config = _RuleConfig();
159159
config.group = asString(key);
160160
config.name = asString(rule);
161-
config.args = parseArgs(args)!;
161+
config.args = parseArgs(args) ?? {};
162162
ruleConfigs.add(config);
163163
});
164164
}

pkg/analyzer/test/src/dart/analysis/analysis_context_collection_test.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,74 @@ workspaces
212212
''');
213213
}
214214

215+
/// Verify the type of invalid data in
216+
/// https://github.com/dart-lang/sdk/issues/55594 doesn't result in unhandled
217+
/// exceptions when building contexts.
218+
test_basicWorkspace_invalidAnalysisOption_issue55594() async {
219+
var workspaceRootPath = '/home';
220+
var testPackageRootPath = '$workspaceRootPath/test';
221+
newFile('$testPackageRootPath/lib/a.dart', '');
222+
223+
newAnalysisOptionsYamlFile(testPackageRootPath, '''
224+
linter:
225+
rules:
226+
- camel_case_types
227+
- file_names
228+
- non_constant_identifier_names
229+
- comment_references
230+
-
231+
''');
232+
233+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
234+
contexts
235+
/home
236+
workspace: workspace_0
237+
analyzedFiles
238+
/home/test/lib/a.dart
239+
analysisOptions_0
240+
workspacePackage_0_0
241+
analysisOptions
242+
analysisOptions_0: /home/test/analysis_options.yaml
243+
workspaces
244+
workspace_0: BasicWorkspace
245+
root: /home
246+
workspacePackage_0_0
247+
''');
248+
}
249+
250+
/// Verify the type of invalid data in
251+
/// https://github.com/dart-lang/sdk/issues/56577 doesn't result in unhandled
252+
/// exceptions when building contexts.
253+
test_basicWorkspace_invalidAnalysisOption_issue56577() async {
254+
var workspaceRootPath = '/home';
255+
var testPackageRootPath = '$workspaceRootPath/test';
256+
newFile('$testPackageRootPath/lib/a.dart', '');
257+
258+
newAnalysisOptionsYamlFile(testPackageRootPath, '''
259+
linter:
260+
rules:
261+
analyzer:
262+
errors:
263+
todo: ignore
264+
''');
265+
266+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
267+
contexts
268+
/home
269+
workspace: workspace_0
270+
analyzedFiles
271+
/home/test/lib/a.dart
272+
analysisOptions_0
273+
workspacePackage_0_0
274+
analysisOptions
275+
analysisOptions_0: /home/test/analysis_options.yaml
276+
workspaces
277+
workspace_0: BasicWorkspace
278+
root: /home
279+
workspacePackage_0_0
280+
''');
281+
}
282+
215283
test_packageConfigWorkspace_enabledExperiment() async {
216284
configuration.withEnabledFeatures = true;
217285

0 commit comments

Comments
 (0)