Simply assuming that $jacocoData
is always the last element is dangerous, as Class#getDeclaredFields()
does not guarantee any order.
To check whether a field is synthetic use Field#isSynthetic()
, so your code can be changed to:
val fields = contract.getClass.getDeclaredFields.
toList.withFilter(!_.isSynthetic()).map(value => {
value.setAccessible(true)
value.getName
})