Make it Break

As a software engineer, creating software is more than just programming. Aside from programming, some key elements of creating good software are testing and quality assurance. In a future post I would like to address the area of testing, but for now let us focus on quality assurance.

Quality Assurance
Quality assurance is just as it reads: assurance of quality. The problem here is that, although code may meet a certain level of quality, the level of quality is very subjective. To ensure a certain level of quality, it is imperative that the exact specifications or standards be well defined so that bad quality code can be easily rectified. There are many methods to ensure quality assurance. Some activities may be manual checks such as code reviews or source code control while others may be automated such as a lint tool. In this posting, I will review my experience creating a MakeItBreak Java class with these three automated quality assurance tools: Checkstyle, PMD, and Findbugs.

Checkstyle
Checkstyle ensures that source code is formatted in a certain way. This means that whether a developer reads his own code or his college’s code, the code formatting will be the same. Now developer can be concerned about actual code rather than formatting idiosyncrasies. An example of a Checkstyle error would be no spaces between an operator such as 1 +1;

PMD
PMD is a source code analyzer to find inefficiencies or dead code. Although this tool may overlap with Checkstyle, this tool will detect unused code such as creating an unused instance.

Findbugs
Findbugs checks for potential bugs in Java code at the byte code level. An example of a checked bug is string comparison using a double equals. Although this may be considered fundamental Java to use the equals method, I have made this error after switching from JavaScript.

Make It Break
For this assignment, I had to create a Java class that have 5 unique errors from each of the tools, Checkstyle, PMD, and Findbugs that can still compile. The whole point behind this exercise is to explore the various rules, understand fundamental differences, and know the limits behind each tool. I have previous experience with these each of these tools, even to the point that I have implemented these tools at STAR.

When going through the list of rules, there seemed to be inconsistencies between the rules defined on the direct website and the rules that are used to check our code. Hopefully, this means that our rule set may be a subset of all the rules rather than a bug in the tools.

Here is my class that has 5 errors for Checkstyle, PMD, and Findbugs:

import java.util.*;
/**
 * This comment will attempt to break checkstyle. this line should not be over 100 characters. blah blah blah blah blah blah blah blah blah blah blah.
 */
public abstract class MakeItBreak {
  public int[] value;
  private Vector vector = new Vector();

  /** I wonder why this class cannot be instantiated? */
  private MakeItBreak() {
    System.out.println(value.toString());
    if (true) {
      System.exit(vector.size());
    }
  }

  /** This should be abstract. **/
  public synchronized void makeItBreak() {
  }

  /** Returns null. */
  public String toString() {
    return null;
  }
}
Advertisements