Common problems and solutions of checkstyle error reporting
Statement:
This article is extracted from Baidu Library. I hope the specifications mentioned in this article can have a good effect on everyone’s programming. This article is updated from time to time and will launch more detailed programming specifications.
1 Prompt: type is missing a Javadoc commentclass
Description: missing type description
Solution: add Javadoc description
2 Prompt: “{” should be on the previous line
Description: ‘{‘ should be on the previous line
Solution: put “{” on the previous line
3 Tips: methos is missing a Javadoc comment
Note: the Javadoc comment is missing in front of the method
Solution: add Javadoc comments
4 Tips: Expected @throws tag for“Exception”
Note: you want a description of @ throws in the comments
Solution: add such a line in the comment before the method: * @ throws exception if has error (exception description)
5 Prompt: “.” is preceded with whitespace
Description: “.” There must be no spaces in front of it
Solution: remove the space before “.”
6 Prompt: “.” is followed by whitespace
Description: ” There must be no spaces after
Solution: remove the space after “.”
7 Prompt: “=” is not preceded with whitespace
Description: “=” Missing space before
Solution: add a space before “=”
8 Prompt: “=” is not followed with whitespace
Description: “=” Missing space after
Solution: add a space after “=”
9 Prompt: “}” should be on the same line
Description: “}” Should be on the same line as the next statement
Solution: put “}” before the next line
10 prompt: unused @ param tag for “unused”
Note: there is no parameter “unused”, and no comment is required
Solution: “* @ param unusedparameter additional (parameter name)” remove the comment of this line of unusedparameter“
11 tips: Variable “CA” missingjavadoc
Description: Javadoc comment is missing for variable “CA”
Solution: add Javadoc comment before “CA” variable:/* * ca. */(Note: be sure to add “.” after Ca.)
12 tips: Line longer than 80characters
Description: the line length exceeds 80 。
Solution: divide it into multiple lines. If necessary, you can Ctrl + Shift + F
13 prompt: line contains a tab character
Description: the line contains the “tab” character
14 prompt: redundant “public” modifier
Description: redundant “public” modifier 。
Solution: redundant “public”
15 prompt: final modifier out of order with the JSL suggestion
Note: the final modifier is in wrong order
16 tips: Avoid using the “.*” formof import
Note: avoid using ‘. *’ in import format
17 prompt: redundant import from the same package
Description: import content from the same package
18 tips: Unusedimport-java.util.list
Note: the java.util.list imported by import is not used
Solution: remove the imported redundant classes
19 prompt: duplicate import to line 13
Description: import the same content repeatedly
Solution: remove the imported redundant classes
20 tips: Import from illegalpackage
Description: import content from illegal package
21 prompt: “while” construct must use “{}”
Description: ‘while’ statement is missing ‘{}’
22 tips: Variable “sTest1” must beprivate and have accessor method
Note: the variable “stest1” should be private and have a method to call it
23 tips: Variable “ABC” must matchpattern “^[a-z][a-zA-Z0-9]*$”
Note: the variable “ABC” does not conform to the naming rule “^ [A-Z] [a-za-z0-9] * $”
Solution: change the name to “ABC” in accordance with the rules
24 prompt: “(” is followed by whitespace ” “)” is proceeded by whitespace
Description: ‘(‘ cannot be followed by a space “)” There must be no spaces before
Solution: remove the space before or after
25 prompt: first sense should end with a period
Solution: 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’. Exceptions are repeatedly thrown
Solution: if two exceptions are thrown, and one exception class is a subclass of the other, you only need to write the parent class
Remove the namenotfoundexception exception and the corresponding Javadoc comment. The exception note also needs to be removed
27 tips: Parameter docType should be final.
Description: Parameter DOCTYPE should be final
Solution: add final before the parameter DOCTYPE
28 tips: Line has trailing spaces.
Description: extra blank lines
Solution: remove this blank line
29 tips: Must have at least onestatement.
Description: At least one declaration
Solution: the exception capture in try {} catch() {} cannot be empty. Add a sentence to the exception. Such as printing, etc
30 prompt: ‘>’ Is not followed by whitespace ‘(‘ is preceded with whitespace.
Description: when defining sets and enumerations, the last “>” There should be a space after “(” and no space before “(“
Solution: get rid of generics (usually where generics are easy to cause this problem)
31 prompt: got an exception – java.lang.runtimeexception: unable to get classinformation for @ throws tag ‘SystemException’
Description: unreasonable throws
Solution: ensure 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 solution: 1. This is the error reported by checkstyle. Usually you need to refresh, 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, just configure the compiled class in & lt; checkstyle/> In addition, I also found that there seems to be a problem with the line length of checkstyle. It clearly does not exceed 120 characters, but it still reports an error. Unfortunately, I put Java > code style > The maximum line with in the format is changed to 100, and then the format is changed. Basically, there is no problem
32 tips: 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
33 prompt: utility classes should not have a public or default constructor
Description: There should be no public or default constructor in the inner class of the interface
Solution: define a private constructor in the inner class, and then declare the inner class as final. If there is static in front of it, final must also be placed after static
34 prompt: variable ‘FUNCTIONCODE’ must be private and have accessor methods
Note: change the. Variable to private, and then provide access methods
Solution: change the modifier 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 be accessed through the method
35 tips: ‘ X’ hides a field.
Description: global private int x; Duplicate the X variable name of local publicfoo (int x)
solution: just change the parameter name in the method. Public foo (int newbar)
36 tips: Got an exception -Unexpected character 0xfffd in identifier
Note: This is because checkstyle cannot recognize the specified coding format
Online reference solution:
1. Eclipse can be configured in other — > You can specify in the 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, add the statement in bold and italics
37 Tips: Got an exception -java.lang.RuntimeException: Unable to get class information for @throws tag*whatever*.
Online reference solution: select Javadoc — > Method JavaDoc –> logLoadErrors。 If there is an error when checkstyle loads itself, just type a log. Don’t make the errors frightening( I haven’t encountered this problem, so I haven’t tried)
there is another possible error. Coding Problems –> Redundant Throws –> Select logloaderrors
38 tips: Expected @param tag for ‘dataManager’.
Description: missing comment for datamanager parameter
Solution: add @ param datamanager datamanager to the comment
Similar Posts:
- Difference between normalize space (.) and normalize space (text ()) in XPath
- Python:IndentationError: expected an indented block
- [Solved] Java Call Error: java.lang.IllegalArgumentException: wrong number of arguments
- Mac open terminal error – bash:: command not found
- Vue solves the problem of space and blank line error reporting
- Ifconfig command not found for Linux Installation Errors [How to Solve]
- Java error: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- [Solved] jenkins checkstyle: local variable hides a field
- [Solved] java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”
- [Solved] oauth2(spring security) Error: method_not_allowed(Request method ‘GET’ not supported)