Fix issue where invalid analysis options file is produced for some tests

R=brianwilkerson@google.com

fixes: https://github.com/dart-lang/sdk/issues/54921
Change-Id: Ib1d7fa2400ea587ff66568efdaec67559cad1e6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352866
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Osama Alraddadi <osama.alraddadi@gmail.com>
diff --git a/pkg/analysis_server/test/abstract_context.dart b/pkg/analysis_server/test/abstract_context.dart
index 93a3fb4..0fd5f2e 100644
--- a/pkg/analysis_server/test/abstract_context.dart
+++ b/pkg/analysis_server/test/abstract_context.dart
@@ -119,39 +119,41 @@
 
   /// Create an analysis options file based on the given arguments.
   void createAnalysisOptionsFile({
-    List<String>? experiments,
-    List<String>? cannotIgnore,
-    List<String>? lints,
-    Map<String, Object?>? errors,
+    List<String> experiments = const [],
+    List<String> cannotIgnore = const [],
+    List<String> lints = const [],
+    Map<String, Object?> errors = const {},
   }) {
     var buffer = StringBuffer();
 
-    if (experiments != null || cannotIgnore != null || errors != null) {
+    if (experiments.isNotEmpty ||
+        cannotIgnore.isNotEmpty ||
+        errors.isNotEmpty) {
       buffer.writeln('analyzer:');
     }
 
-    if (errors != null) {
+    if (errors.isNotEmpty) {
       buffer.writeln('  errors:');
       for (var error in errors.entries) {
         buffer.writeln('    ${error.key}: ${error.value}');
       }
     }
 
-    if (experiments != null) {
+    if (experiments.isNotEmpty) {
       buffer.writeln('  enable-experiment:');
       for (var experiment in experiments) {
         buffer.writeln('    - $experiment');
       }
     }
 
-    if (cannotIgnore != null) {
+    if (cannotIgnore.isNotEmpty) {
       buffer.writeln('  cannot-ignore:');
       for (var unignorable in cannotIgnore) {
         buffer.writeln('    - $unignorable');
       }
     }
 
-    if (lints != null) {
+    if (lints.isNotEmpty) {
       buffer.writeln('linter:');
       buffer.writeln('  rules:');
       for (var lint in lints) {