Skip to content

Commit 09b84bc

Browse files
Fix: Ensure non-nullable Map for FunctionCallPart.args
Resolves a compilation type mismatch: "inferred type is ...HashMap<String, String?>? but Map<String, String?> was expected". This indicated that the SDK's `FunctionCallPart` constructor expects a non-nullable `Map<String, String?>` for its `args` parameter. The `PartDto.toSdk()` mapper for `FunctionCallPartDto` has been updated. If the DTO's `args` field is `null`, an empty `Map<String, String?>` is now passed to the `FunctionCallPart` constructor. Otherwise, the DTO's `args` map is converted to a non-nullable `Map<String, String?>`. This ensures the SDK constructor always receives a non-null Map instance, satisfying the type requirement and fixing the build failure.
1 parent 161c967 commit 09b84bc

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/feature/multimodal/dtos/PhotoReasoningMappers.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ fun PartDto.toSdk(): Part { // No context needed here as path is absolute
5656
}
5757
is BlobPartDto -> BlobPart(mimeType = this.mimeType, blob = this.data)
5858
is FunctionCallPartDto -> {
59-
val sdkArgs: HashMap<String, String?>? = this.args?.let { dtoArgs ->
60-
// Explicitly create a HashMap.
61-
val newMap = hashMapOf<String, String?>()
62-
dtoArgs.entries.forEach { entry ->
59+
val sdkArgs: Map<String, String?> = if (this.args == null) {
60+
emptyMap<String, String?>() // Provide an empty map if DTO.args is null
61+
} else {
62+
// If DTO.args is not null, create a new map from it.
63+
// Values in this.args can be null, matching Map<String, String?>.
64+
val newMap = mutableMapOf<String, String?>()
65+
this.args.entries.forEach { entry ->
6366
newMap[entry.key] = entry.value
6467
}
65-
newMap
68+
newMap.toMap() // Return immutable, non-null map
6669
}
6770
FunctionCallPart(name = this.name, args = sdkArgs)
6871
}

0 commit comments

Comments
 (0)