JakeWharton / RxBinding

RxJava binding APIs for Android's UI widgets.
Apache License 2.0
9.68k stars 971 forks source link

Null parameter when disposing a custom View written in Kotlin #457

Closed Orbyt closed 6 years ago

Orbyt commented 6 years ago

Given a simple custom view:

class Button @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    init {
        View.inflate(context, R.layout.button, this)
    }

    override fun setOnClickListener(listener: View.OnClickListener) =
        button.setOnClickListener(listener)
}

When this View is used in an Activity with RxBinding, an eventual call to View#setOnClickListener passing null would result in the View's setOnClickListener method to be invoked with a null argument, causing the following error:

Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull

JakeWharton commented 6 years ago

Change your override to accept a nullable listener. null is a valid value here.