Question

Locked

Annoying Java warnings

By G... ·
Hi all!

I'm currently working on a Java project and I have a "problem". I'm using Eclipse and get hundreds of warnings stating: "the filed ... is never read locally". That is quite right but I still nead those fields for Spring, webwork or velocity.

So I would like to know if someone found a solution (or workaround) other than: "@SuppressWarnings("unused")" or turning off these warnings in Eclipse?

Thank you.

Geo

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

setting in Preferences

by webjabber In reply to Annoying Java warnings

Preferences menus, Java->Compiler, Unused Code tab. You can set ignore there.


WebJabber

A secure path to access your servers.

http://www.gotoservers.com

Collapse -

No settings

by G... In reply to setting in Preferences

As I said in my first post, I don't want to turn it off because it sometime is helpful.

Collapse -

What is wrong with SuppressWarning("unused") ?

by jslarochelle In reply to No settings

This is the clean way to turn this warning off selectively. Other than turning off the warning in the preference menu (not a good idea) I don't know of any other "sane" way to do this.
Well maybe you could use the PMD pluggin and I think this tool includes a warning for this violation and that can be turned off by using a special comment. Then you could turn the warning off in the Eclipse preference and still get a warning in the PMD tab. However, this is going to a lot of trouble to perform something that can be done with a simple annotation.

Collapse -

I think it's alright but...

by G... In reply to What is wrong with Suppre ...

The person in charge of the program doesn't like it. He wants a "better" solution. So I try to find one. I use suppressWarning("unused") for myself but I'm not allowed to commit code to the repository with those.
So I check if someone has heard of something that could do the trick.

Thanks anyway.

Collapse -

Of course I assume that your use of unused variables is

by jslarochelle In reply to I think it's alright but. ...

justified (although it seems strange). I`m not using any of the technologies mentionned in your initial message so I have to trust you on this.
Another way to deal with this and maybe satisfy the person in charge might be to write your own annotation. Something like SuppressWarningMotivation with an enum parameter for Spring and the other tools your using. You could use SuppressWarning and SuppressWarningMotivation (you would have to use RUNTIME retention for this one) and in your JUnit tests check that the unused field are used with Spring (for example). That way you could prevent any abuse of the SuppressWarning annotation because you could demand that any use of it requires the use of the SuppresWarningMotivation and this could be used in JUnit test to validate the whole thing. This would probably require pretty fancy test code (using the reflection API) but might be possible.
Yet another way to deal with this might be to use AspectJ to "weave in" the code (in this case data members) for Spring at compile time.
This is the end of the road for me on this one.
Good luck
JS

Back to Software Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums