Showing 108 of 130 total issues
Extra separation in import group before 'org.redalert1741.powerup.TankDrive' Open
import org.redalert1741.powerup.TankDrive;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'}' at column 53 should be alone on a line. Open
public void stop() { /* brake more continues */ }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks the placement of right curly braces ('}'
) for code blocks.This check supports if-else, try-catch-finally blocks, while-loops, for-loops,method definitions, class definitions, constructor definitions,instance, static initialization blocks, annotation definitions and enum definitions.For right curly brace of expression blocks of arrays, lambdas and class instancesplease follow issue#5945.For right curly brace of enum constant please follow issue#7519.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Member name 'i' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. Open
private int i;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that instance variable names conform to a specified pattern.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'}' at column 51 should be alone on a line. Open
public MovePojo() { /* gson wants this */ }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks the placement of right curly braces ('}'
) for code blocks.This check supports if-else, try-catch-finally blocks, while-loops, for-loops,method definitions, class definitions, constructor definitions,instance, static initialization blocks, annotation definitions and enum definitions.For right curly brace of expression blocks of arrays, lambdas and class instancesplease follow issue#5945.For right curly brace of enum constant please follow issue#7519.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Parameter name 'a' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. Open
public static Class<AutoFactory> addMoveEnd(String name, AutoMoveEndFactory a) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that method parameter names conform to a specified pattern.By using accessModifiers
property it is possibleto specify different formats for methods at different visibility levels.
To validate catch
parameters please useCatchParameterName.
To validate lambda parameters please useLambdaParameterName.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Only one statement per line allowed. Open
ammf.put(name, a); return AutoFactory.class;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there is only one statement per line.
Rationale: It's very difficult to read multiple statements on one line.
In the Java programming language, statements are the fundamental unit ofexecution. All statements except blocks are terminated by a semicolon.Blocks are denoted by open and close curly braces.
OneStatementPerLineCheck checks the following types of statements:variable declaration statements, empty statements, import statements,assignment statements, expression statements, increment statements,object creation statements, 'for loop' statements, 'break' statements,'continue' statements, 'return' statements, resources statements (optional).
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Extra separation in import group before 'org.redalert1741.powerup.Manipulation' Open
import org.redalert1741.powerup.Manipulation;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'}' at column 56 should be alone on a line. Open
public void stop() { /* EmptyMove does not stop */ }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks the placement of right curly braces ('}'
) for code blocks.This check supports if-else, try-catch-finally blocks, while-loops, for-loops,method definitions, class definitions, constructor definitions,instance, static initialization blocks, annotation definitions and enum definitions.For right curly brace of expression blocks of arrays, lambdas and class instancesplease follow issue#5945.For right curly brace of enum constant please follow issue#7519.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Extra separation in import group before 'java.io.FileNotFoundException' Open
import java.io.FileNotFoundException;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'}' at column 13 should be alone on a line. Open
} while(moves.get(i-1).isAsync());
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks the placement of right curly braces ('}'
) for code blocks.This check supports if-else, try-catch-finally blocks, while-loops, for-loops,method definitions, class definitions, constructor definitions,instance, static initialization blocks, annotation definitions and enum definitions.For right curly brace of expression blocks of arrays, lambdas and class instancesplease follow issue#5945.For right curly brace of enum constant please follow issue#7519.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Parameter name 'a' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. Open
public static Class<AutoFactory> addMoveMove(String name, AutoMoveMoveFactory a) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that method parameter names conform to a specified pattern.By using accessModifiers
property it is possibleto specify different formats for methods at different visibility levels.
To validate catch
parameters please useCatchParameterName.
To validate lambda parameters please useLambdaParameterName.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Replace this use of System.out or System.err by a logger. Open
System.out.println("1t: "+manip.getFirstStageAtTop());
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
When logging a message there are several important requirements which must be fulfilled:
- The user must be able to easily retrieve the logs
- The format of all logged message must be uniform to allow the user to easily read the log
- Logged data must actually be recorded
- Sensitive data must only be logged securely
If a program directly writes to the standard outputs, there is absolutely no way to comply with those requirements. That's why defining and using a dedicated logger is highly recommended.
Noncompliant Code Example
System.out.println("My Message"); // Noncompliant
Compliant Solution
logger.log("My Message");
See
- CERT, ERR02-J. - Prevent exceptions while logging data
Replace this use of System.out or System.err by a logger. Open
System.out.println("2b: "+manip.getSecondStageAtBottom());
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
When logging a message there are several important requirements which must be fulfilled:
- The user must be able to easily retrieve the logs
- The format of all logged message must be uniform to allow the user to easily read the log
- Logged data must actually be recorded
- Sensitive data must only be logged securely
If a program directly writes to the standard outputs, there is absolutely no way to comply with those requirements. That's why defining and using a dedicated logger is highly recommended.
Noncompliant Code Example
System.out.println("My Message"); // Noncompliant
Compliant Solution
logger.log("My Message");
See
- CERT, ERR02-J. - Prevent exceptions while logging data
Replace this use of System.out or System.err by a logger. Open
System.out.println("1b: "+manip.getFirstStageAtBottom());
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
When logging a message there are several important requirements which must be fulfilled:
- The user must be able to easily retrieve the logs
- The format of all logged message must be uniform to allow the user to easily read the log
- Logged data must actually be recorded
- Sensitive data must only be logged securely
If a program directly writes to the standard outputs, there is absolutely no way to comply with those requirements. That's why defining and using a dedicated logger is highly recommended.
Noncompliant Code Example
System.out.println("My Message"); // Noncompliant
Compliant Solution
logger.log("My Message");
See
- CERT, ERR02-J. - Prevent exceptions while logging data
Remove duplicates in this character class. Open
Pattern itemPattern = Pattern.compile("^#{0}([\\w\\d_]+)\\s*?=\\s*?(.+)$");
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Character classes in regular expressions are a convenient way to match one of several possible characters by listing the allowed characters or ranges of characters. If the same character is listed twice in the same character class or if the character class contains overlapping ranges, this has no effect.
Thus duplicate characters in a character class are either a simple oversight or a sign that a range in the character class matches more than is
intended or that the author misunderstood how character classes work and wanted to match more than one character. A common example of the latter
mistake is trying to use a range like [0-99]
to match numbers of up to two digits, when in fact it is equivalent to [0-9]
.
Another common cause is forgetting to escape the '-
' character, creating an unintended range that overlaps with other characters in the
character class.
Noncompliant Code Example
str.matches("[0-99]") // Noncompliant, this won't actually match strings with two digits str.matches("[0-9.-_]") // Noncompliant, .-_ is a range that already contains 0-9 (as well as various other characters such as capital letters)
Compliant Solution
str.matches("[0-9]{1,2}") str.matches("[0-9.\\-_]")
Define a constant instead of duplicating this literal "min-auto.json" 5 times. Open
autoChoice = "min-auto.json";
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
public void run() { prepare("action1"); // Noncompliant - "action1" is duplicated 3 times execute("action1"); release("action1"); } @SuppressWarning("all") // Compliant - annotations are excluded private void method1() { /* ... */ } @SuppressWarning("all") private void method2() { /* ... */ } public String method3(String a) { System.out.println("'" + a + "'"); // Compliant - literal "'" has less than 5 characters and is excluded return ""; // Compliant - literal "" has less than 5 characters and is excluded }
Compliant Solution
private static final String ACTION_1 = "action1"; // Compliant public void run() { prepare(ACTION_1); // Compliant execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Remove this useless assignment to local variable "autoChoice". Open
String autoChoice = "empty-auto.json";
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it's not an error, it is at best a waste of resources. Therefore all calculated values should be used.
Noncompliant Code Example
i = a + b; // Noncompliant; calculation result not used before value is overwritten i = compute();
Compliant Solution
i = a + b; i += compute();
Exceptions
This rule ignores initializations to -1, 0, 1, null
, true
, false
and ""
.
See
- MITRE, CWE-563 - Assignment to Variable without Use ('Unused Variable')
- CERT, MSC13-C. - Detect and remove unused values
- CERT, MSC56-J. - Detect and remove superfluous code and values
This block of commented-out lines of code should be removed. Open
int position = findPosition(); //config.getSetting("auto_position", -1.0).intValue();
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
Refactor this method to reduce its Cognitive Complexity from 24 to the 15 allowed. Open
public void teleopPeriodic() {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.
See
This block of commented-out lines of code should be removed. Open
// if(manip.getFirstStageAtBottom()) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.