Hi all! I’m getting a weird `AbstractMethodError` ...
# announcements
d
Hi all! I’m getting a weird
AbstractMethodError
when I try to call a
fun interface
method with Kotlin 1.5:
Copy code
// definition
fun interface OnItemClickListener {
  fun onChannelClicked(channelId: ChannelId)
}

internal var clickListener: OnItemClickListener? = null

// callsite
holder.itemView.setOnClickListener {
  clickListener?.onChannelClicked(channelId)
                 // ^^^ line 63, crash here
}
                
// Runtime crash
java.lang.AbstractMethodError: abstract method "void path.to.ChannelItemViewAdapter$OnItemClickListener.onChannelClicked-Grz9ttw(java.lang.String)"
  at path.to.ChannelItemViewAdapter.onBindViewHolder$lambda-3$lambda-2(ChannelItemViewAdapter.kt:63)
  at path.to.ChannelItemViewAdapter.lambda$CKDKaveMGRwL-cim-kOMtD1bOuU(Unknown Source:0)
  
// decompiled Kotlin
public interface OnItemClickListener {
  void onChannelClicked_Grz9ttw/* $FF was: onChannelClicked-Grz9ttw*/(@NotNull String var1);
}

public final void onClick(View it) {
  ChannelItemViewAdapter.OnItemClickListener var10000 = this.this$0.getClickListener$communication_debug();
  if (var10000 != null) {
    var10000.onChannelClicked-Grz9ttw(this.$this_with.getChannelId-WlYWy3A());
  }
}
Any idea what the culprit might be here?
e
ChannelId is an inline/value class?
d
Yes,
ChannelId
is a
value class
, might this be the culprit?
Forgot to mention this.
I don’t see more than “abstract method” in the exception message, which is puzzling. There are a couple of issues listed wrt
fun interfaces
in the bugtracker, but none really fits my issue: https://youtrack.jetbrains.com/issue/KT-37866
e
is everything being compiled with the same version of Kotlin?
the name mangling scheme changed somewhat recently, https://kotlinlang.org/docs/inline-classes.html#mangling
d
Yes, everything is compiled with the same Kotlin version.
I’ll try and use the old mangling scheme, just see if this is the issue.
No, even with
-Xuse-14-inline-classes-mangling-scheme
in
freeCompilerArgs
I run into the same error.
I’ll open up a bugreport for this one.
As always, a minimal reproducer does not crash, sigh
Copy code
@JvmInline
value class Foo(private val inner: String)

fun interface Callback {
    fun doSomething(foo: Foo)
}

fun main() {
    val bla = Callback {
        println(it)
    }

    bla.doSomething(Foo("Hello world!"))
}
Off to the weekend, need fresh eyes on this one.
This seem to have been a temporary glitch on the callsite. I had something like this:
Copy code
with(binding.messageList) {
    val channelAdapter = ChannelItemViewAdapter()
    adapter = channelAdapter
    ...
    channelAdapter.clickListener = ChannelItemViewAdapter.OnItemClickListener { channelId ->
        viewModel.onChannelClicked(channelId)
    }
}
and when I called
.javaClass.methods
on the
channelAdapter.clickListener
afterwards, I saw indeed an abstract method:
Copy code
result = {Method[11]@37369} 
 0 = {Method@37370} "public boolean java.lang.Object.equals(java.lang.Object)"
 ...
 5 = {Method@37375} "public abstract void path.to.ChannelItemViewAdapter$OnItemClickListener.onChannelClicked-Grz9ttw(java.lang.String)"
 6 = {Method@37376} "public final void path.to.MyFragment$onCreateView$1$2.onChannelClicked-Grz9ttw-Grz9ttw(java.lang.String)"
 ...
where method
37376
was obviously the right, but wrongly named one. When I moved code a little back and forth, this abstract method vanished and I couldn’t reproduce the issue any longer 😞
Wait, I found the issue - the code is wrongly generated if
Copy code
channelAdapter.clickListener = ChannelItemViewAdapter.OnItemClickListener {
    viewModel.onChannelClicked(it)
}
is used instead of
Copy code
channelAdapter.clickListener = ChannelItemViewAdapter.OnItemClickListener { channelId ->
    viewModel.onChannelClicked(channelId)
}
Gna, no, adding some debug code after this makes it vanish again.
I created a bug report for this: https://youtrack.jetbrains.com/issue/KT-47158