[go: nahoru, domu]

Allow nullable boolean array in safe args

While you should not be able to give a boolean a default value of null
you should be able to make an array default to null. We need to enable
safe args to generate boolean array with nullable values.

RelNote: "Fixed a bug in safe args that would not allow boolean arrays
to have a `null` value."
Test: modified NavParserTest
Bug: 174787525

Change-Id: I8c396c8f174d5924bb5ee147261de158256fba94
diff --git a/navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/Types.kt b/navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/Types.kt
index 0da8969..0c9e1eb 100644
--- a/navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/Types.kt
+++ b/navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/Types.kt
@@ -121,7 +121,7 @@
     override fun bundlePutMethod() = "putBooleanArray"
     override fun bundleGetMethod() = "getBooleanArray"
     override fun toString() = "boolean"
-    override fun allowsNullable() = false
+    override fun allowsNullable() = true
 }
 
 object ReferenceType : NavType {
diff --git a/navigation/navigation-safe-args-generator/src/test/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt b/navigation/navigation-safe-args-generator/src/test/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt
index 329e73c..e0c1609 100644
--- a/navigation/navigation-safe-args-generator/src/test/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt
+++ b/navigation/navigation-safe-args-generator/src/test/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt
@@ -69,6 +69,7 @@
                                 "android.content.pm.ActivityInfo"
                             )
                         ),
+                        Argument("booleanArrayArg", BoolArrayType, NullValue, true),
                         Argument(
                             "enumArg",
                             ObjectType("java.nio.file.AccessMode"),
diff --git a/navigation/navigation-safe-args-generator/src/test/test-data/naive_test.xml b/navigation/navigation-safe-args-generator/src/test/test-data/naive_test.xml
index 50542fc..8f5bd65 100644
--- a/navigation/navigation-safe-args-generator/src/test/test-data/naive_test.xml
+++ b/navigation/navigation-safe-args-generator/src/test/test-data/naive_test.xml
@@ -35,6 +35,7 @@
             <argument android:name="intArrayArg" app:argType="integer[]"/>
             <argument android:name="stringArrayArg" app:argType="string[]"/>
             <argument android:name="objectArrayArg" app:argType="android.content.pm.ActivityInfo[]"/>
+            <argument android:name="booleanArrayArg" android:defaultValue="@null" app:argType="boolean[]" app:nullable="true" />
             <argument android:name="enumArg" app:argType="java.nio.file.AccessMode"
                       android:defaultValue="READ"/>
             <argument android:name="objectRelativeArg" app:argType=".pkg.ClassName"/>