🐛 Bug Report: Kotlin server SDK does not properly process nullable values when mapping #667
Closed
2 tasks done
Labels
bug
Something isn't working
👟 Reproduction steps
When I try to fetch teams list using Teams object, I get NPE.
Demo code:
👍 Expected behavior
Teams list should load.
👎 Actual Behavior
The call crashes with following stack trace:
I've investigated the crash and found the point. The error occurs in mapping the Team object's preferences in Team.kt file:
In last line, where prefs is assigned, actual value of maps["prefs"] is null, while cast expects it to be Map<String, Any>. So the prefs field in data class Team should be nullable, and I suggest that the cast should be rewritten, something like that:
I've checked the
sdk-generator
project and found that all models, when processing maps or lists of maps, always assume that the input value is not nullable, while it actually can be null (and so this is true for corresponding fields in data classes, which have to be nullable too).Here is example from
templates/kotlin/src/main/kotlin/io/appwrite/models/Model.kt.twig
, line 64, where aforementioned code for Kotlin Server SDK is being generated:Unfortunately due to my lack of knowledge of Twig or PHP stops me from creating proper pull-request for this feature, so I hope that someone will be able to fix this in future releases.
I've created similar issue in
sdk-for-kotlin
repo before discovering this repo, so please remove that issue if it is not required anymore: appwrite/sdk-for-kotlin#30.🎲 Appwrite version
Different version (specify in environment)
💻 Operating system
MacOS
🧱 Your Environment
I use
io.appwrite:sdk-for-kotlin:2.0.0
which automatically fetches all required dependencies.👀 Have you spent some time to check if this issue has been raised before?
🏢 Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: