StackOverflowError with data binding lambda expression


#1

Hi,

I have a few lambda expression already. But I try to add one for android:onLongClick. But the build fails

error: cannot generate view binders java.lang.StackOverflowError
at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt)
at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt)
at android.databinding.tool.ext.LazyExt.getValue(ext.kt:27)
at android.databinding.tool.writer.LayoutBinderWriterKt.getCallbackLocalName(LayoutBinderWriter.kt)
at android.databinding.tool.writer.LayoutBinderWriterKt.scopedName(LayoutBinderWriter.kt:200)
at android.databinding.tool.expr.Expr.toCode(Expr.java:739)
at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt:206)
at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt)
at android.databinding.tool.ext.LazyExt.getValue(ext.kt:27)
at android.databinding.tool.writer.LayoutBinderWriterKt.getCallbackLocalName(LayoutBinderWriter.kt)
at android.databinding.tool.writer.LayoutBinderWriterKt.scopedName(LayoutBinderWriter.kt:200)
at android.databinding.tool.expr.Expr.toCode(Expr.java:739)

…you get the picture
Now in the layout I have the activity bound and try to set android:onLongClick, this should be supported

<data>
    <variable name="context" type="letstwinkle.com.twinkle.ProspectsActivity" />
    <variable name="quiz" type="letstwinkle.com.twinkle.model.ProspectQuiz" />
</data>
    <TextView
        android:onLongClick="@{() -> context.quizLongClicked(quiz)}"
        />

I bind this attribute in one other layout like this:

        android:onLongClick="@{activity::matchPlayAvatarLongPressed}"

So seems like method reference is OK, but Kotline not handling a lambda properly for a synthetic attribute? Plus similar expression for android:onClick works.


#2

This is an issue with the databinding compiler, not with Kotlin. The Kotlin compiler is not involved in any way with compiling the databinding expressions in layout XML files.


#3

So the class android.databinding.tool.writer.LayoutBinderWriterKt. is implemented by the data binding library developers?


#4

Yes.


#5

hmm

I think you just have an error in your xml :
1 - Does quizLongClicked return a boolean ?
2 - have you tried using something else than context for your variable name ? databinding already allows you to use context in order to refer to root.context, so it sounds like naming your variable context can only lead to issues.

(and that would not work in java either)


#6

After checking, I found a signature error. I updated the method, stopped getting the SO error.