Groovy static type-checking still allows access to private fields?

70 Views Asked by At

I'm using Groovy's static type checking to enforce protection of my application from its configuration scripts.

Is it normal that the script can still access private fields, even with static type checking enabled?

Debugging in the code, I see that the access ends up in StaticTypeCheckingVisitor.hasAccessToMember where receiver and accessor are both set to the destination class but I would have expected that accessor is the script class...

1

There are 1 best solutions below

1
Andrej Istomin On

Yes, it is normal. Groovy doesn't generally cares about visibility, see this blog post You wonder probably how it's even possible... because Groovy uses Reflection API. Here is the SO question about it.