This annotation will fail your build ⚠️💀

Google’s data-binding library for Android lets you build layouts which react to external data changes. If you have used this library, you probably already know what an ObservableField is. If you don’t, to keep it really simple, there are two ways to expose observable properties for a layout:

Subclass BaseObservable and annotate the properties with @Bindable Use ObservableField<T>, where T is your value’s type

But this post isn’t about data-binding basics, it’s about how we updated to data-binding v3.1.0 and broke our Kotlin code.

In the new version of library, ObservableField’s get() method is annotated with @Nullable. Why is this a big deal? Because now every time you do ObservableField#get() and use the value, you need to perform a null check, or use the ?. safe call operator — even if you’re never setting the value to null.

val foo = ObservableField("")



// type is `String?` even though value is never set to null

val fooValue: String? = foo.get()

Given the number of such method calls in our codebase, this is going to result in a ton of unnecessary null checks.