Adam Heath wrote:
> Scott Gray wrote:
>> On 4/02/2010, at 11:41 PM, Adam Heath wrote:
>>
>>> I'll also be looking for java code formatting tools; anyone have any
>>> suggestions that are apache compatible(has to be free, won't use
>>> commercial things at all(don't get me started on confluence)).
>> PMD (http://pmd.sourceforge.net/) uses a BSD style license and may be worth 
>> a look.
> 
> Hmm.  Looking at controversial rulesets makes me interested; I bet the
> other rulesets are equally enjoyable.  Thanks, will try it out.

Oh, PMD, how I love thee, let me count the ways.  Oh, whoops, I just
had a StackOverFlow.  I guess that means I've finally found my true
love.  Let's get married and make beautiful babies together.  Then,
they can all become leaders of all the countries of the world, and we
will achieve world dominiation.

In a word, I <blink>LOVE</blink> PMD.

Based on the example rules I read about on their site, here are some
things that we could scan for(code issues):

==
String var;
// this should use UtilValidate
if (var != null && var.length > 0);
==
Collection var;
// this should use UtilValidate
if (var != null && var.isEmpty());
==
public boolean equals(Object o) {
    // This throws a ClassCastException, which is not
    // what the contract for this method allows.
    MyClass other = (MyClass) o;
==
// This loop should stay an iterator/while combo.  PMD
// can detect the remove call.  Any other loops can be
// recommended for using enhanced-for
Iterator it = collection.iterator();
while (it.hasNext()) {
    // code block
    it.remove();
    // code block
}
==
// should use valueOf
new Integer(5);
==
// should be new BigDecimal(".1")
new BigDecimal(.1);
==
// when pulling from the database, the string variant
// should be used, not the double variant.  double
// values are not exact.
double d = .1;
new BigDecimal(d);
==
// don't concat vars in append() calls
new StringBuilder().append("foo" + 1 + "bar");
==

ps: The BigDecimal checks are not something I knew about.  Those
actually already exist for PMD, and I was surprised to read about
them.
http://pmd.sourceforge.net/rules/basic.html#AvoidDecimalLiteralsInBigDecimalConstructor

pps: Upon further scanning, PMD doesn't appear to do space checks.
Bother.  So I am still looking for something to do that.

Reply via email to