Interpreting Checkstyle errors

When we start working with classes, Codecheck will often contain a Checkstyle section. Checkstyles checks that your Javadoc is correctly written. If not, i will give you an error message. An error message doesn't do you much good unless you can decode it. Here is some help.

This class produces Checkstyle errors

1  public class PiggyBank
2  {
3      private double total;
4    
5      /**
6       * Creates a empty PiggyBank with a total of 0
5       */
8      public PiggyBank()
9      {
10         total = 0;
11    }
12    
13    /**
14     * Adds this amount to the total in this PiggyBank
15     * @param the amount to add
16     */
17    public void add(double amount) 
18    {
19         total = total + amount;
20    }
21    /**
22     * subtracts this amount from the total in this PiggyBank
23     * @param amount  the amount to remove
24     */
25    public void remove(double amount)
26    {
27         total = total - amount;
28    }
28    
30    /**
31     * Gets the total for this PiggyBank
32     * 
33     */
34    public double getTotal() 
35    {
36        return total;
37    }
38 }

Let's see what they mean:

1.

Error message
/tmp/codecheck/17010206026172739420624521759/submission/PiggyBank.java:1: Missing a Javadoc comment.
Significant part java:1: Missing a Javadoc comment
Meaning On line #1, a Javadoc comment is missing. You need a comment for the class itself
Fix Add a comment at the top of the class
Code /**
* models a child's piggy bank to which money can be
* added and removed
*/

2.

Error message
/tmp/codecheck/17010206026172739420624521759/submission/PiggyBank.java:15:8: Unused @param tag for 'the'.
Significant part
java:15:8: Unused @param tag for 'the'
Meaning

On line #15, you have @param the ...

The first word after the @param should be one of the parameters in the parentheses of the method. This is the method header

public void add(double amount) 

the parameter name is amount

Fix remove the @param for "the"
Code  

3.

Error message
/tmp/codecheck/17010206026172739420624521759/submission/PiggyBank.java:17:28: Expected @param tag for 'amount'.
Significant part java:17:28: Expected @param tag for 'amount'.
Meaning

This is related to the previous error

On line #17, there is a parameter in the parameters in the parentheses of the method, but there is no @param for that parameter. This is the method header

public void add(double amount) 
Fix add an @param for "amount"
Code

Add this to the Javadoc for the method

 @param  amount the amount to add

4.

Error message
/tmp/codecheck/17010206026172739420624521759/submission/PiggyBank.java:34: Expected an @return tag.
Significant part
java:34: Expected an @return tag.
Meaning

On line #34, there is a method header with a type parameter other than "void". Here is the method header

public double getTotal() 
Fix You need to add the @return to explain what the method returns
Code

Add this to the Javadoc for the method header

 @return the total amount in this PiggyBank

 

Last Modified: Feb 22, 2023