contentful / vault

Easy persistence of Contentful data for Android over SQLite.
https://contentful.github.io/vault/
Apache License 2.0
85 stars 19 forks source link

Use @Nullable annotation when possible #153

Closed ashenriques closed 4 years ago

ashenriques commented 5 years ago

all the fields that might return a "null" value, should be annotated as such.

For instance, on the class "FetchQuery" the method "first" should use the annotation.

Otherwise this code crashes in Kotlin:

fun getExampleByID(exampleID: String) = vault.fetch(ExampleCF::class.java).where("${ExampleCF$Fields.REMOTE_ID} = \"$exampleID\"").first()

fun doSomethingWithExample(example: ExampleCF) : String = example.toString()

fun causeCrash() = doSomethingWithExample(getExampleByID("non existing id"))

since Kotlin is not expecting that getExampleByID might in any case return a null value, when the ID doesn't exist and that's what vault actually returns, Kotlin will try to cast a null to a non-null object causing a crash

mariobodemann commented 5 years ago

Adding those annotations is a great idea.

Sadly due to time constraints, I cannot tell you anything about the timeline when this might happen in the SDK.

Sofar, please treat any responses from the SDK as nullable.

rafalniski commented 4 years ago

Will take that into the consideration when implementing new code. Unfortunately, there is no plan for now to refactor current codebase.