Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cfca5ea

Browse files
committed
Fix NPE when describing a function in the info builder
I didn't track it down, but throwing an exception here appears to cause the migration engine or preview tool to hang. It was preventing the flutter package from being migrated. Change-Id: I0c2454fce5622a9768c2e3ff69514f83ffcd8a3f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129180 Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
1 parent 6aa995d commit cfca5ea

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

pkg/analysis_server/lib/src/edit/nnbd_migration/info_builder.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,21 @@ class InfoBuilder {
688688
} else {
689689
baseDescription = "the function";
690690
}
691+
} else if (node is FieldDeclaration) {
692+
var field = node.thisOrAncestorOfType<VariableDeclaration>();
693+
if (field == null) {
694+
field = node.fields.variables[0];
695+
}
696+
functionName = field.name.name;
697+
baseDescription = "the field";
698+
} else {
699+
// Throwing here allows us to gather more information. Not throwing here
700+
// causes an NPE on line 709.
701+
throw ArgumentError("Can't describe function in ${node.runtimeType}");
691702
}
692703
}
693704

694-
ClassMember enclosingClassMember = node.thisOrAncestorOfType<ClassMember>();
705+
var enclosingClassMember = node.thisOrAncestorOfType<ClassMember>();
695706

696707
if (enclosingClassMember != null) {
697708
describeFunction(enclosingClassMember);

0 commit comments

Comments
 (0)