Java: Effect of @NonNull function returning null

41 Views Asked by At

I have an old Java function in an Android project that is annotated with @NonNull. A few years after the function was written another developer added a branch that returns null and forgot to remove the annotation. This was discovered a few months later - I'm surprised the compiler didn't stop that from happening.

What potential issues could this or a similar situation cause, if any? Could this undermine null-safety when interoperating with Kotlin?

1

There are 1 best solutions below

1
Gabe Sechan On

It should cause a compile error. But if a null is passed into a not nullable kotlin value, it would eventually lead to a crash when someone tried to dereference it.