Status Update
Comments
ch...@google.com <ch...@google.com> #2
Hello,
Thank you for reaching out to us with your request.
We have duly noted your feedback and will thoroughly validate it. While we cannot provide an estimated time of implementation or guarantee the fulfillment of the issue, please be assured that your input is highly valued. Your feedback enables us to enhance our products and services.
We appreciate your continued trust and support in improving our Google Cloud Platform products. In case you want to report a new issue, Please do not hesitate to create a new issue on the
Once again, we sincerely appreciate your valuable feedback; Thank you for your understanding and collaboration.
lu...@gmail.com <lu...@gmail.com> #3
Will be any communication to me when google starts working on this feature?
ch...@google.com <ch...@google.com> #4
Thanks for sharing the reproduction.
The problem is that the toString()
implementation of the lambda ::requestLoad
will reflectively lookup the method invoked by the lambda. This happens in the implementation of kotlin.jvm.internal.FunctionReference.toString()
, which also explains why this method shows up in the stack trace:
kotlin.NotImplementedError: Function 'requestLoad' (JVM signature: requestLoad(Ljava/lang/Integer;)V) not resolved in class net.kusik.r8funrefissue.LazyListPaging: no members found
at kotlin.reflect.jvm.internal.KTypeImpl$$Lambda$1.invoke(SourceFile:1297)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(SourceFile:19)
at kotlin.reflect.jvm.internal.KFunctionImpl.getDescriptor(SourceFile:3)
at kotlin.reflect.jvm.internal.KFunctionImpl.toString(SourceFile:3)
at kotlin.jvm.internal.FunctionReference.toString(SourceFile:7)
at java.lang.String.valueOf(String.java:2924)
at java.lang.StringBuilder.append(StringBuilder.java:132)
at net.kusik.r8funrefissue.Snapshot.toString(Unknown Source:19)
at java.lang.String.valueOf(String.java:2924)
at net.kusik.r8funrefissue.MainActivity$onCreate$1$1$1.invoke(SourceFile:59)
The method called by the lambda is LazyListPaging.requestLoad(Integer)
. This method is only called from LazyListPaging.access$requestLoad(LazyListPaging, Integer)
, which is only called from LazyListPaging$snapshot$1.invoke(Integer)
. Therefore, the two requestLoad
methods are inlined by R8 into the invoke
method (after which they are removed, since there are no more calls to them). The problem now arises since the toString()
implementation reflectively looks up the requestLoad
method. In order for this to succeed, the method must be kept:
-keepclassmembers class net.kusik.r8funrefissue.LazyListPaging {
private void requestLoad(java.lang.Integer);
}
The constructor of the kotlinc generated lambda looks as follows. In principle it would be possible to model in R8 that FunctionReference
will reflect on the method specified by the arguments. This way R8 could in principle automatically synthesize the about rule. However, this would likely have a significant negative impact on code size (e.g., it would prohibit requestLoad
from being eliminated), so I don't see us pursuing this idea, unless this would only apply to certain opt-in lambdas.
.method public constructor <init>(Ljava/lang/Object;)V
.locals 7
const/4 v1, 0x1
const-class v3, Lnet/kusik/r8funrefissue/LazyListPaging;
const-string v4, "requestLoad"
const-string v5, "requestLoad(Ljava/lang/Integer;)V"
const/4 v6, 0x0
move-object v0, p0
move-object v2, p1
invoke-direct/range {v0 .. v6}, Lkotlin/jvm/internal/FunctionReference;-><init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
return-void
.end method
From a code size perspective, it is also quite wasteful to store the strings "requestLoad"
and "requestLoad(Ljava/lang/Integer;)V"
on the lambda instance when they are unused. Ideally this would be optimized better.
Description
My app is crashing on release builds with the following error:
Example code:
In the stacktrace, it seems that a call to the .toString() function of the Snapshot data class tries to describe the onLoad function property, which is a reference to the LazyListPaging.requestLoad() function that was thrown out.