Test-driven source code formatting
steele.blue·761w
Preview
Report Post

May 2, 2011

This morning, I had to fight a production error in an application I support. It turns out that using SELECT * statements with Spring JDBC can cause problems when you add new columns to the table. It has something to do with Oracle caching; I’m not sure.

So, SELECT * statements are evil. But how do you ensure your codebase doesn’t contain any? Being a good test-driven developer, I wanted to have a failing test before making wide swaths of changes to my source code. The solution I settled on was to write a new static analysis rule, using Checkstyle, to warn me when it identified a SELECT * statement. Here’s what it looks like (you can put this in a Checkstyle v5 xml file):

<module name="RegexpSinglelineJava">
<property name="format" value="SELECT.*[\. ]\*"/>...

Similar Posts

Loading similar posts...