Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warning “Access to field exceeds its access rights” in Groovy

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

like image 892
k13i Avatar asked May 13 '19 11:05

k13i


1 Answers

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

like image 183
Dmitry Khamitov Avatar answered Nov 14 '22 09:11

Dmitry Khamitov