Static Code Analyzers

I’m trying to use static code analyzers to streamline my code and make it more readable. The code’s supposed to be open source, and I want it to actually be useable.

This isn’t about performance so much as usability, but I wasn’t sure where else to put this.

I’ve been getting my static code analyzers in the form of eclipse plug-ins.

First, I tried Unnecessary Code Detector (http://www.ucdetector.org/). This worked pretty well. I shut off all the warnings about changing visibility because most of them seemed unimportant, but I found the plug-in useful for removing unused code. It also helped me find a few class stubs that I had created with the intention of implementing specific features. I now have these specific features listed on my todo list so that I can implement them.

It also has the ability to check for dependency cycles (where class A calls class B and class B also calls class A). Limiting dependencies is desireable, though I didn’t do much with this. It simply wasn’t worth the time sorting out the mess. Some of the cycles are perfectly acceptable for various reasons.

Second, I tried PMD (http://pmd.sourceforge.net/). This found a ridiculous number of problems, most of which seem to be about obscure code style issues that seem somewhat arbitrary to me. I am changing some of my code to match their naming conventions and such, but many of the warnings appear to be unimportant.

Does anyone have any advice about any other static code analyzer plug-ins to use or any comments about their experiences with static code analysis?

Haha I have never had any code problems. I usually set rules for what my naming and code style should be when I work on something so my code is always neat and tidy when I look back :smiley:

I used pmd but found it too annoying.

I basically just use findbugs.

I’m installing Find Bugs and will try it out tomorrow or Friday. Even if it just catches a couple of things I want to change, it’s worth trying out.

Thanks!

The community edition of IntelliJ IDEA has everything you need, except duplicate code detection. Everything’s configurable too, so for example you can automatically format your code the way you like, use only the inspections that are interesting to you, etc.

Oh yes IntelliJ IDEA also was quite good in picking things that findbugs missed.

Find Bugs appears to be working out ok. It isn’t going to change anything drastically, but I’m rearranging some of my code. It’s relatively easy to locate problems with all these tools unless they find a superabundance of warnings about nothing. Fortunately, you can turn most of that stuff off.

I don’t think I want to go so far as to switch to a different IDE to get better static code analyzers. It looks like I can use the IntelliJ IDEA for free because I’m making an open source game, but I don’t want to encounter problems if I suddenly decide to use the same engine to make a shareware game. I could just buy the IDE, but I don’t want it badly enough.

[quote=“fletchergames,post:7,topic:36710”]
That only applies to the Ultimate edition, which is really targeted to web/enterprise development. You can use the Community edition just like you use Eclipse. Going all the way and switching IDEs is very hard for any developer and a personal matter really, bu in this case I highly recommended giving IDEA a try. You could at least use it on the side just for its inspection and quick-fix features.

eclipse warnings -> Find Bugs -> PMD

generally I have no eclipse or find bugs warnings
having no PMD warnings should be impossible, I think its a great tool, just don’t take it too seriously

although find bugs has a problem with java 7, in that every System.out or .err are null pointer for it
kinda annoying