Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Arrow tries (and fails) to set final fields via reflection #10

Open
hcoles opened this issue Dec 4, 2019 · 1 comment
Open

Arrow tries (and fails) to set final fields via reflection #10

hcoles opened this issue Dec 4, 2019 · 1 comment
Assignees

Comments

@hcoles
Copy link

hcoles commented Dec 4, 2019

I maintain http://pitest.org, a mutation testing system for java, which is also being increasingly used with kotlin.

Pitest includes a block coverage system, the implementation of which adds a synthetic static final field to each class.

This causes a runtime error with arrow as it attempts to write to the final field via reflection.

The problem can be reproduced in the following repo by running gradlew pitest

https://github.com/Octogonapus/reproduce-pitest-problem

Unfortunately I don't speak kotlin, and have only a hazy idea of what arrow is trying to achieve, but it seems likely that it should avoid writing to synthetic fields (and probably also final static ones).

If it does need to write to final fields then

https://github.com/arrow-kt/arrow/blob/master/modules/core/arrow-core-data/src/main/kotlin/arrow/typeclasses/ContinuationUtils.kt

should first change the field's modifier as well as making it accessible. e.g.

it.getModifiers() & ~Modifier.FINAL

Arrow seems to work ok with jacoco as the probe field it adds to classes is non final. There may be issues with other coverage systems however (and would be with jacoco for interfaces, as the jvm spec requires final fields in this case, but I don't know enough about arrow to know if this is a valid scenario).

@pakoito pakoito self-assigned this Dec 4, 2019
@pakoito
Copy link
Member

pakoito commented Dec 4, 2019

Thank you for the report. I'll take a look ASAP. We're migrating away from the reflection hack (which I assure you is necessary 🙃) soon-ish, maybe we can have a point release with the fix.

Congratulations on Pitest by the way. I did not know it and it looks POWERFUL 🤩

Octogonapus referenced this issue in Octogonapus/arrow Dec 10, 2019
@rachelcarmena rachelcarmena transferred this issue from arrow-kt/arrow Feb 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants