-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash in state restoration with multiple of 32 fields #707
Fix crash in state restoration with multiple of 32 fields #707
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the fix and test 🙏
@Test | ||
fun testClassWithExactly32Parameters() { | ||
data class StateWith32Params( | ||
val p0: Int = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -128,7 +128,7 @@ fun <T : MavericksState> restorePersistedMavericksState( | |||
val fieldCount = constructor.parameterTypes.size | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be simpler to round up to the next int ceil(fieldCount/32.0).toInt()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.