Fix crash in state restoration with multiple of 32 fields#707
Fix crash in state restoration with multiple of 32 fields#707rossbacher merged 2 commits intomainfrom
Conversation
… be be too high (e.g. 2 with field count 32 and 3 with field count 64) leading to a crash when calling the copyt function via reflection. Added test that tests that case.
elihart
left a comment
There was a problem hiding this comment.
thanks for the fix and test 🙏
| @Test | ||
| fun testClassWithExactly32Parameters() { | ||
| data class StateWith32Params( | ||
| val p0: Int = 0, |
There was a problem hiding this comment.
does it matter that there are only 16 persist state annotations here? it's confusing why only half of the params have it, but I suppose it shouldn't matter for the purposes of this bug?
There was a problem hiding this comment.
It's the number of parameters in the constructor that trigger the bug not the number of persisted elements, I copied this from another test, that is why this is like this, but we could also persist them all or persist none of them.
The test was failing before the fix.
|
|
||
| // There is 1 bitmask for each block of 32 parameters. | ||
| val parameterBitMasks = IntArray(fieldCount / 32 + 1) { 0 } | ||
| val parameterBitMasks = IntArray(fieldCount / 32 + if (fieldCount % 32 != 0) 1 else 0) { 0 } |
There was a problem hiding this comment.
might be simpler to round up to the next int ceil(fieldCount/32.0).toInt()
There was a problem hiding this comment.
Yeah, that was what I was looking for yesterday but could not come up with it. I'll update it.
If the field count is exactly multiples of 32 the bitmap count would be be too high (e.g. 2 with field count 32 and 3 with field count 64) leading to a crash when calling the copy function via reflection.
Added test that tests that case.