I write a Groovy script and I need to access a field that has a private access modifier. This works fine but generates a warning:

Access to <field_name> exceeds its access rights

I want to supress this warning. What value of @SuppressWarnings annotation do I have to use in order to achieve it?

I've tried @SuppressWarnings("all") and it works fine but I would like to have more granular control over suppressions. I've also tried @SuppressWarnings("AccessingNonPublicFieldOfAnotherObject") but it has no effect.

Below how this warning looks in IntelliJ:

Warning in IntelliJ

Unfortunately automatic hint doesn't suggest any sensible solution:

IntelliJ hints

1 Answers

Dmitry Khamitov On Best Solutions

If you are talking about IntelliJ warning:

enter image description here

then you can hit Alt+Enter on the offender and choose "Suppress for method" as follows:

enter image description here

after which you will see @SuppressWarnings("GroovyAccessibility") over your test method:

enter image description here