Open adrian-shape opened 11 months ago
This bug seems to do with name resolution by the compiler. The implementation of the build function in the anonymous object somehow resolves value to the string property, rather than to the double parameter. Some questions:
doubleWrapperBuilder
to the companion objectIs this problem the same if you just create the object without using serialization (but it being serializable)
I just created the object manually with StringWrapper("1.0").double
, not using serialization, but it still crashes.
If I remove both annotations, the issue no longer appears.
What happens if you don't make the class a data class
With both data classes being converted to regular classes, same crash appears.
What happens if you move the doubleWrapperBuilder to the companion object
In both scenarios if I move the entire doubleWrapperBuilder value to the companion object everything works fine. If I move the lambda to the companion object and assign it in the constructor, it works fine too.
I guess could have something to do with creating the lambda in the constructor with @Transient
Describe the bug
When you have a
@Serializable
class with a@Transient
lambda, the lambda captures the wrong parameters. The code compiles just fine, but crashes during runtime.To Reproduce
If we have the following class, and call
StringWrapper("1.0").double
Then this is the result:
If I remove the annotations, the code behaves as expected.
If I change the argument names inside DoubleWrapperBuilder to not clash, then the code behaves as expected.
I have also in some other iteration of this bug with different usage gotten a ClassCastException from String to Number while having Java code involved.
Expected behavior
Calling the .double function as specified should not crash.
Environment