<p>What code analysis tools do you use on your Java projects?</p>

<p>I am interested in all kinds</p>

<ul>
<li>static code analysis tools (FindBugs, PMD, and any others)</li>
<li>code coverage tools (Cobertura, Emma, and any others)</li>
<li>any other instrumentation-based tools </li>
<li>anything else, if I'm missing something</li>
</ul>

<p>If applicable, also state what build tools you use and how well these tools integrate with both your IDEs and build tools. </p>

<p>If a tool is only available a specific way (as an IDE plugin, or, say, a build tool plugin) that information is also worth noting.</p>

[{'answer_id': 4166, 'author': 'ggasp', 'author_id': 527, 'author_profile': 'https://Stackoverflow.com/users/527', 'pm_score': 1, 'selected': False, 'text': "<p>We use FindBugs and JDepend integrated with Ant. We use JUnit but we're not using any coverage tool. </p>\n\n<p>I'm not using it integrated to Rational Application Developer (the IDE I'm using to develop J2EE applications) because I like how neat it looks when you run javac in the Windows console. :P</p>\n"}, {'answer_id': 4492, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://checkstyle.sourceforge.net/" rel="noreferrer">Checkstyle</a> is another one I\'ve used at a previous company... it\'s mainly for style checking, but it can do some static analysis too.  Also, <a href="http://www.atlassian.com/software/clover/" rel="noreferrer">Clover</a> for code coverage, though be aware it is not a free tool.</p>\n'}, {'answer_id': 4493, 'author': 'dlinsin', 'author_id': 198, 'author_profile': 'https://Stackoverflow.com/users/198', 'pm_score': 2, 'selected': False, 'text': "<p>We are using FindBugs and Checkstyle as well as Clover for Code Coverage. </p>\n\n<p>I think it's important to have some kind of static analysis, supporting your development. Unfortunately it's still not widely spread that these tools are important.</p>\n"}, {'answer_id': 6022, 'author': 'Joshua McKinnon', 'author_id': 235, 'author_profile': 'https://Stackoverflow.com/users/235', 'pm_score': 0, 'selected': False, 'text': '<p>I am looking for many answers to learn about new tools and consolidate this knowledge in a one question/thread, so I doubt there will be 1 true answer to this question.</p>\n\n<p>My answer to my own question is that we use:</p>\n\n<ul>\n<li>Findbugs to look for common errors bad/coding - run from maven, and also integrates easily into Eclipse</li>\n<li>Cobertura for our coverage reports - run from maven</li>\n</ul>\n\n<p>Hudson also has a task-scanner plugin that will display a count of your TODO and FIXMEs, as well as show where they are in the source files.</p>\n\n<p>All are integrated with Maven 1.x in our case and tied into Hudson, which runs our builds on check-in as well as extra things nightly and weekly. Hudson trend graphs our JUnit tests, coverage, findbugs, as well as open tasks. There is also a Hudson plugin that reports and graphs our compile warnings. We also have several performance tests with their own graphs of performance and memory use over time using the Hudson plots plugin as well.</p>\n'}, {'answer_id': 13277, 'author': 'Brian Laframboise', 'author_id': 1557, 'author_profile': 'https://Stackoverflow.com/users/1557', 'pm_score': 4, 'selected': False, 'text': '<p>All of the following we use and integrate easiy in both our Maven 2.x builds and Eclipse/RAD 7:</p>\n\n<ul>\n<li>Testing - JUnit/TestNG</li>\n<li>Code analysis - FindBugs, PMD</li>\n<li>Code coverage - Clover</li>\n</ul>\n\n<p>In addition, in our Maven builds we have:</p>\n\n<ul>\n<li>JDepend</li>\n<li>Tag checker (TODO, FIXME, etc)</li>\n</ul>\n\n<p>Furthermore, if you\'re using Maven 2.x, CodeHaus has a collection of handy Maven plugins in their <a href="http://mojo.codehaus.org/plugins.html" rel="noreferrer">Mojo project</a>.</p>\n\n<p>Note: Clover has out-of-the-box integration with the Bamboo CI server (since they\'re both Atlassian products). There are also Bamboo plugins for FindBugs, PMD, and CheckStyle but, as noted, the free Hudson CI server has those too.</p>\n'}, {'answer_id': 79845, 'author': 'Greg Mattes', 'author_id': 13940, 'author_profile': 'https://Stackoverflow.com/users/13940', 'pm_score': 7, 'selected': True, 'text': '<p>For static analysis tools I often use CPD, <a href="http://pmd.sourceforge.net" rel="noreferrer">PMD</a>, <a href="http://findbugs.sourceforge.net" rel="noreferrer">FindBugs</a>, and <a href="http://checkstyle.sourceforge.net" rel="noreferrer">Checkstyle</a>.</p>\n\n<p><p>CPD is the PMD "Copy/Paste Detector" tool. I was using PMD for a little while before I noticed the <a href="http://pmd.sourceforge.net/cpd.html" rel="noreferrer">"Finding Duplicated Code" link</a> on the <a href="http://pmd.sourceforge.net" rel="noreferrer">PMD web page</a>.</p>\n\n<p><p>I\'d like to point out that these tools can sometimes be extended beyond their "out-of-the-box" set of rules. And not just because they\'re open source so that you can rewrite them. Some of these tools come with applications or "hooks" that allow them to be extended. For example, PMD comes with the <a href="http://pmd.sourceforge.net/howtowritearule.html" rel="noreferrer">"designer" tool</a> that allows you to create new rules. Also, Checkstyle has the <a href="http://checkstyle.sourceforge.net/config_misc.html#DescendantToken" rel="noreferrer">DescendantToken</a> check that has properties that allow for substantial customization.</p>\n\n<p><p>I integrate these tools with <a href="http://virtualteamtls.svn.sourceforge.net/viewvc/virtualteamtls/trunk/scm/common.xml?view=markup" rel="noreferrer">an Ant-based build</a>. You can follow the link to see my commented configuration.</p>\n\n<p><p>In addition to the simple integration into the build, I find it helpful to configure the tools to be somewhat "integrated" in a couple of other ways. Namely, report generation and warning suppression uniformity. I\'d like to add these aspects to this discussion (which should probably have the "static-analysis" tag also): how are folks configuring these tools to create a "unified" solution? (I\'ve asked this question separately <a href="https://stackoverflow.com/questions/79918/configuring-static-analysis-tools-for-uniformity">here</a>)</p>\n\n<p><p>First, for warning reports, I transform the output so that each warning has the simple format:</p>\n\n<pre><code>/absolute-path/filename:line-number:column-number: warning(tool-name): message</code></pre>\n\n<p><p>This is often called the "Emacs format," but even if you aren\'t using Emacs, it\'s a reasonable format for homogenizing reports. For example:</p>\n\n<pre><code>/project/src/com/example/Foo.java:425:9: warning(Checkstyle):Missing a Javadoc comment.</code></pre>\n\n<p><p>My warning format transformations are done by my Ant script with Ant <a href="http://ant.apache.org/manual/Types/filterchain.html" rel="noreferrer">filterchains</a>.</p>\n\n<p><p>The second "integration" that I do is for warning suppression. By default, each tool supports comments or an annotation (or both) that you can place in your code to silence a warning that you want to ignore. But these various warning suppression requests do not have a consistent look which seems somewhat silly. When you\'re suppressing a warning, you\'re suppressing a warning, so why not always write "<code>SuppressWarning</code>?"</p>\n\n<p><p>For example, PMD\'s default configuration suppresses warning generation on lines of code with the string "<code>NOPMD</code>" in a comment. Also, PMD supports Java\'s <code>@SuppressWarnings</code> annotation. I configure PMD to use comments containing "<code>SuppressWarning(PMD.</code>" instead of <code>NOPMD</code> so that PMD suppressions look alike. I fill in the particular rule that is violated when using the comment style suppression:</p>\n\n<pre><code>// SuppressWarnings(PMD.PreserveStackTrace) justification: (false positive) exceptions are chained</code></pre>\n\n<p><p>Only the "<code>SuppressWarnings(PMD.</code>" part is significant for a comment, but it is consistent with PMD\'s support for the <code>@SuppressWarning</code> annotation which does recognize individual rule violations by name:</p>\n\n<pre><code>@SuppressWarnings("PMD.CompareObjectsWithEquals") // justification: identity comparision intended</code></pre>\n\n<p><p>Similarly, Checkstyle suppresses warning generation between pairs of comments (no annotation support is provided). By default, comments to turn Checkstyle off and on contain the strings <code>CHECKSTYLE:OFF</code> and <code>CHECKSTYLE:ON</code>, respectively. Changing this configuration (with Checkstyle\'s "SuppressionCommentFilter") to use the strings "<code>BEGIN&nbsp;SuppressWarnings(CheckStyle.</code>" and "<code>END&nbsp;SuppressWarnings(CheckStyle.</code>" makes the controls look more like PMD:</p>\n\n<pre>\n<code>// BEGIN SuppressWarnings(Checkstyle.HiddenField) justification: "Effective Java," 2nd ed., Bloch, Item 2</code>\n<code>// END SuppressWarnings(Checkstyle.HiddenField)</code>\n</pre>\n\n<p><p>With Checkstyle comments, the particular check violation (<code>HiddenField</code>) <em>is</em> significant because each check has its own "<code>BEGIN/END</code>" comment pair.</p>\n\n<p><p>FindBugs also supports warning generation suppression with a <code>@SuppressWarnings</code> annotation, so no further configuration is required to achieve some level of uniformity with other tools. Unfortunately, Findbugs has to support a custom <code>@SuppressWarnings</code> annotation because the built-in Java <code>@SuppressWarnings</code> annotation has a <code>SOURCE</code> retention policy which is not strong enough to retain the annotation in the class file where FindBugs needs it. I fully qualify FindBugs warnings suppressions to avoid clashing with Java\'s <code>@SuppressWarnings</code> annotation:</p>\n\n<pre><code>@edu.umd.cs.findbugs.annotations.SuppressWarnings("UWF&#95;FIELD&#95;NOT&#95;INITIALIZED&#95;IN&#95;CONSTRUCTOR")</code></pre>\n\n<p><p>These techniques makes things look reasonably consistent across tools. Note that having each warning suppression contain the string "<code>SuppressWarnings</code>" makes it easy to run a simple search to find all instances for all tools over an entire code base.</p>\n'}, {'answer_id': 80009, 'author': 'Randyaa', 'author_id': 9518, 'author_profile': 'https://Stackoverflow.com/users/9518', 'pm_score': 1, 'selected': False, 'text': "<p>I've had good luck with Cobertura.  It's a code coverage tool which can be executed via your ant script as part of your normal build and can be integrated into Hudson.</p>\n"}, {'answer_id': 83955, 'author': 'Steve McLeod', 'author_id': 2959, 'author_profile': 'https://Stackoverflow.com/users/2959', 'pm_score': 3, 'selected': False, 'text': '<p>I use the static analysis built into IntelliJ IDEA. Perfect integration.</p>\n\n<p>I use the code coverage built into Intellij IDEA (based on EMMA). Again, perfect integration.</p>\n\n<p>This integrated solution is reliable, powerful, and easy-to-use compared to piecing together tools from various vendors.</p>\n'}, {'answer_id': 84013, 'author': 'vaske', 'author_id': 16039, 'author_profile': 'https://Stackoverflow.com/users/16039', 'pm_score': 1, 'selected': False, 'text': "<p>Our team use PMD and Cobertura, actually our projects are maven projects and there is very simple to include plug ins for code analysis. The real question would be for specific project which analysis you need to use, my opinion is that it's you couldn't use the same plugins for each project.</p>\n"}, {'answer_id': 247984, 'author': 'Ken Liu', 'author_id': 25688, 'author_profile': 'https://Stackoverflow.com/users/25688', 'pm_score': 4, 'selected': False, 'text': '<p>I use a combination of Cobertura, Checkstyle, (Ecl)Emma and Findbugs.</p>\n\n<p><a href="http://www.eclemma.org/" rel="noreferrer">EclEmma</a> is an <em>awesome</em> Eclipse plugin that shows the code coverage by coloring the java source in the editor (<a href="http://www.eclemma.org/images/screen.png" rel="noreferrer">screenshot</a>) - the coverage is generated by running a JUnit test. This is really useful when you are trying to figure out which lines are covered in a particular class, or if you want to see just which lines are covered by a single test. This is much more user friendly and useful than generating a report and then looking through the report to see which classes have low coverage.</p>\n\n<p>The Checkstyle and Findbugs Eclipse plugins are also useful, they generate warnings in the editor as you type.</p>\n\n<p>Maven2 has report plugins that work with the above tools to generate reports at build time. We use this to get overall project reports, which are more useful when you want aggregate numbers. These are generated by our CI builds, which run using <a href="http://continuum.apache.org/" rel="noreferrer">Continuum</a>.</p>\n'}, {'answer_id': 3594285, 'author': 'OneCent', 'author_id': 434162, 'author_profile': 'https://Stackoverflow.com/users/434162', 'pm_score': 1, 'selected': False, 'text': '<p>in our project we use Sonar in front of checkstyle, pmd.... together with the CI (Bamboo, Hudson) we get also a nice history of our source quality and what directing we go. I do like Sonar, because you one central tool in the CI Stack that does it for you, and you can easy customize the rules for each project.</p>\n'}, {'answer_id': 7453067, 'author': 'Jeffrey Lee', 'author_id': 844555, 'author_profile': 'https://Stackoverflow.com/users/844555', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.headwaysoftware.com/" rel="nofollow">Structure 101</a> is good at code analysis and finding the cyclic package dependencies.</p>\n'}]
['https://Stackoverflow.com/questions/4080', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/235/']