Kotlin codegen generates code which causes "unnecessary safe call on a non-null receiver of type
Sample codegen where it throws error during build
data class _Backrefs(
val __typename: String = "CentreBackrefs",
val stores__via__centre: List?
) {
fun marshaller(): ResponseFieldMarshaller = ResponseFieldMarshaller.invoke { writer ->
writer.writeString(RESPONSE_FIELDS[0], this@_Backrefs.__typename)
writer.writeList(RESPONSE_FIELDS[1], this@_Backrefs.stores__via__centre) { value,
listItemWriter ->
value?.forEach { value ->
listItemWriter.writeObject(value?.marshaller())}
}
}
stores__via__centre list item is expecting it to be nullable but its not and is causing build to fail. Have tried invalidating cache, rebuild, clean and try to re-generate without much sucess
Screenshot of issue

Issue is similar in 12 other queries across the android app, and it was working fine with 1.4.5
Version info:
apolloGradlePlugin = "2.0.0"
androidGradlePlugin = "3.6.3"
Hi, this is definitely something we should fix but the screenshot and the report looks like a warning rather than an error.
If the compilation is failing, there must be another error. Can you have another look?
I'm guessing @mmahesh2019 has kotlinOptions.allWarningsAsErrors = true. We are seeing the same compilation failures.
Thanks for clarifying. I'm going to set kotlinOptions.allWarningsAsErrors = true in our tests and will prevent this from happening in the future.
Just to clarify. No behavior has changed here. Since we converted API to Kotlin, Kotlin Compiler has more knowledge about nullability. That's why we have extra warnings now. They are not because of any change in code generation.
Most helpful comment
Just to clarify. No behavior has changed here. Since we converted API to Kotlin, Kotlin Compiler has more knowledge about nullability. That's why we have extra warnings now. They are not because of any change in code generation.