Common problems and solutions for CheckStyle errors

Common problems and solutions for CheckStyle errors

1 Warning: Type is missing a javadoc commentClass

Description: Missing type description

Solution: add javadoc description

2 Warning: “{” should be on the previous line

Explanation: “{” should be on the previous line.

Solution: put “{” on the previous line

3 Warning: Methos is missing a javadoc comment

Explanation: The javadoc comment is missing in front of the method.

Solution: add javadoc comments

4 Warning: Expected @throws tag for “Exception”

Description: I hope @throws in the comments

Solution: Add this line in the comment before the method: * @throws Exception if has error (exception description)

5 Warning: “.” Is preceeded with whitespace

Note: There can be no spaces before “.”.

Solution: remove the space in front of “.”

6 Warning: “.” Is followed by whitespace

Note: There can be no spaces after “.”.

Solution: remove the space after “.”

7 Warning: “=” is not preceeded with whitespace

Explanation: Missing spaces before “=”.

Solution: add a space in front of “=”

8 Warning: “=” is not followed with whitespace

Explanation: Missing spaces after “=”.

Solution: add a space after “=”

9 Warning: “}” should be on the same line

Explanation: “}” should be on the same line as the next statement.

Solution: put “}” in front of the next line

10 Warning: Unused @param tag for “unused”

Note: There is no parameter “unused”, no comment is required

Solution: “* @param unusedparameter additional(parameter name)” Remove the comment of this line of unused parameter “

11 Warning: Variable “CA” missingjavadoc

Explanation: The variable “CA” lacks javadoc comments

Solution: Add a javadoc comment before the “CA” variable: /** CA. */ (Note: Be sure to add the “.” after CA)

12 Warning: Line longer than 80characters

Explanation: The line length exceeds 80.

Solution: divide it into multiple lines to write. When necessary, you can ctrl+shift+f

13 Warning: Line contains a tab character

Note: The line contains the “tab” character.

14 Warning: Redundant “Public” modifier

Description: Redundant “public” modifier.

Solution: redundant “public”

15 Warning: Final modifier out of order with the JSL suggestion

Explanation: The order of the Final modifier is wrong

16 Warning: Avoid using the “.*” formof import

Note: Avoid using “.*” in Import format

17 Warning: Redundant import from the same package

Description: Import content from the same package

18 Warning: Unusedimport-java.util.list

Explanation: The java.util.list imported by Import is not used.

Solution: remove the imported redundant classes

19 Warning: Duplicate import to line 13

Description: Repeat Import the same content

Solution: remove the imported redundant classes

20 Tips: Import from illegalpackage

Description: Import content from illegal package

21 Warning: “while” construct must use “{}”

Explanation: The “while” statement is missing “{}”

22 Warning: Variable “sTest1” must beprivate and have accessor method

Description: The variable “sTest1” should be private, and there is a way to call it

23 Warning: Variable “ABC” must matchpattern “^[az][a-zA-Z0-9]*$”

Explanation: The variable “ABC” does not conform to the naming rule “^[az][a-zA-Z0-9]*$”

Solution: Change this name to the name “aBC” that complies with the rules

24 Warning: “(” is followed by whitespace “)” is proceeded by whitespace

Note: “(” cannot be followed by spaces and “)” cannot be preceded by spaces

Solution: remove the spaces before or after

25 Warning: First sentence should end with a period.

Solution: You should add a “.” at the end of the first line of your comment.

26 Tips: Redundant throws:’NameNotFoundException’ is subclass of’NamingException’.

Description:’NameNotFoundException’ is a subclass of’NamingException’ that repeatedly throws exceptions.

Solution: If two exceptions are thrown, one exception class is a subclass of the other, then only the parent class needs to be written

Remove the NameNotFoundException exception, the corresponding javadoc comment exception comment also needs to be removed

27 Warning: Parameter docType should be final.

Description: The parameter docType should be final

Solution: add a final in front of the parameter docType

28 Warning: Line has trailing spaces.

Description: Extra blank lines

Solution: remove this blank line

29 Warning: Must have at least onestatement.

Description: At least one statement

Solution: The exception catch in try{}catch(){} cannot be empty, add a sentence to the exception. Such as printing

30 Warning:’>’ is not followed by whitespace. And there is'(‘is preceded with whitespace.

Note: When defining collections and enumerations, there must be spaces after the last “>”, and spaces before “(” are not allowed.

Solution: remove the generic type (usually generic types are prone to this problem)

31 Warning: Got an exception-java.lang.RuntimeException: Unable to get classinformation for @throws tag’SystemException’.

Explanation: Unreasonable throws.

Solution: Make sure that certain types, such as certain classes and interfaces, are not thrown. Remove the declared exception. Throw an exception in the implementation class

Online reference solutions: 1. This is an error reported by CheckStyle. Usually need to Refreh, clean/build this Project. If not, you can try clean all projects, restart Eclipse.

2. Because the compiled class is not in the classpath of checkstyle. So, as long as the compiled class is configured in the classpath of <checkstyle/>, there is no such problem. In addition, I also found that the line length of checkstyle seems to be a bit problematic. , Obviously there is no more than 120 characters, but it still reports an error. I have no choice but to change the Maximumline with in java> code style> formatter in Eclipse to 100, and then format it, there is basically no problem

32 Warning: File does not end with anewline.

Solution: delete the error-reporting class, create a new class with the same name, and copy all the code over

33 Warning: Utility classes should not have a public or default constructor.

Note: There should not be public or default construction methods in the inner class in the interface

Solution: In the inner class, define a private construction method, and then declare the inner class as a final type. If there is static before, then final must also be placed after static

34 Warning: Variable’functionCode’ must be private and have accessor methods

Description: The variable should be changed to private and then provide access method

Solution: Change the modifiers of these variables to private, then provide set and get methods, and add corresponding method javadoc comments and parameter comments. And add final before the return value and parameter type. And change the place where this variable is called to access by method

35 Warning:’X’ hides a field.

Note: The global private int X; and the local publicFoo (int X) X variable names are the same.
Solution: Change the parameter name in the method to public Foo(int newBar)

36 Warning: Got an exception -Unexpected character 0xfffd in identifier

Note: This is because CheckStyle does not recognize the established encoding format.

Online reference solution:

1. It can be configured in Eclipse, and can be specified in Other–>checker

2. You can modify the checkstyle configuration file:

<modulename=”Checker”>

<propertyname=”severity” value=”warning”/>

<property name=”charset”value=”UTF-8″/>

<modulename=”TreeWalker”>

If it is UTF-8, just add the sentence in bold and italic, and that’s it.

37 Warning: Got an exception -java.lang.RuntimeException: Unable to get class information for @throws tag*whatever*.

Solution: CheckSytle JavaDoc –> Method JavaDoc –> logLoadErrors. if it is CheckStyle own loading errors, a Log on it, do not the whole Errors scare people. (This problem has not been encountered, so did not try)
Coding Problems –> Redundant Throws –> logLoadErrors check the same error.

38 Warning: Expected @param tag for ‘dataManager’.
Explanation: Missing comment for dataManager parameter

Solution: Add @param dataManager DataManager to the comment

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *