Apollo-android: Android Kotlin codegen does not compile after 2.0.0 upgrade

Created on 24 Apr 2020  路  4Comments  路  Source: apollographql/apollo-android

Kotlin codegen generates code which causes "unnecessary safe call on a non-null receiver of type " for queries after 2.0.0 upgrade

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
Screen Shot 2020-04-24 at 3 48 20 pm

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"

Bug

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sav007 picture sav007  路  4Comments

juliafu1 picture juliafu1  路  4Comments

doums picture doums  路  3Comments

moritzmorgenroth picture moritzmorgenroth  路  4Comments

john-lanticse picture john-lanticse  路  3Comments