ModelMetadata
has 61 methods (exceeds 50 allowed). Consider refactoring. Open
@ThreadSafe
@SuppressWarnings({"WeakerAccess", "unused", "OptionalUsedAsFieldOrParameterType"})
public final class ModelMetadata {
private ModelMetadata() { /* Disallow construction. */ }
- Create a ticketCreate a ticket
Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. Open
static @Nonnull <E> Optional<FieldPointer> resolveAnnotatedField(@Nonnull Descriptor descriptor,
- 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
Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed. Open
static @Nonnull <V> FieldContainer<V> pluckFieldRecursive(@Nonnull Message original,
- 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
Define a constant instead of duplicating this literal "Recursive remaining stack should not be null
." 3 times. Open
Objects.requireNonNull(remaining, "Recursive remaining stack should not be `null`.");
- 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.
Define a constant instead of duplicating this literal "Cannot resolve field from null
descriptor." 5 times. Open
Objects.requireNonNull(descriptor, "Cannot resolve field from `null` descriptor.");
- 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.
Define a constant instead of duplicating this literal "Cannot resolve field from null
path." 3 times. Open
Objects.requireNonNull(path, "Cannot resolve field from `null` path.");
- 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.
'...' is preceded with whitespace. Open
public static boolean matchAnyRole(@Nonnull Message model, @Nonnull DatapointType ...types) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there is no whitespace before a token. Morespecifically, it checks that it is not preceded with whitespace, or(if linebreaks are allowed) all characters on the line before arewhitespace. To allow linebreaks before a token, set propertyallowLineBreaks
to true
. No check occursbefore semi-colons in empty for loop initializers or conditions.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'...' is preceded with whitespace. Open
@Nonnull DatapointType ...types) throws InvalidModelType {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there is no whitespace before a token. Morespecifically, it checks that it is not preceded with whitespace, or(if linebreaks are allowed) all characters on the line before arewhitespace. To allow linebreaks before a token, set propertyallowLineBreaks
to true
. No check occursbefore semi-colons in empty for loop initializers or conditions.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
Line is longer than 120 characters (found 121). Open
public static @Nonnull SortedSet<FieldContainer<Object>> pluckAll(@Nonnull Message instance, @Nonnull FieldMask mask) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for long lines.
Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'static' modifier out of order with the JLS suggestions. Open
public final static class FieldContainer<V> implements Serializable, Comparable<FieldContainer<V>> {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that the order of modifiers conforms to the suggestions inthe JavaLanguage specification, § 8.1.1, 8.3.1, 8.4.3 and9.4. The correct order is:
public
protected
private
abstract
default
static
final
transient
volatile
synchronized
native
strictfp
In additional, modifiers are checked to ensure all annotations aredeclared before all other modifiers.
Rationale: Code is easier to read if everybody follows a standard.
ATTENTION: We skiptype annotations from validation.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'...' is preceded with whitespace. Open
public static boolean matchAnyRole(@Nonnull Descriptor descriptor, @Nonnull DatapointType ...types) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there is no whitespace before a token. Morespecifically, it checks that it is not preceded with whitespace, or(if linebreaks are allowed) all characters on the line before arewhitespace. To allow linebreaks before a token, set propertyallowLineBreaks
to true
. No check occursbefore semi-colons in empty for loop initializers or conditions.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'static' modifier out of order with the JLS suggestions. Open
public final static class FieldPointer implements Serializable, Comparable<FieldPointer> {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that the order of modifiers conforms to the suggestions inthe JavaLanguage specification, § 8.1.1, 8.3.1, 8.4.3 and9.4. The correct order is:
public
protected
private
abstract
default
static
final
transient
volatile
synchronized
native
strictfp
In additional, modifiers are checked to ensure all annotations aredeclared before all other modifiers.
Rationale: Code is easier to read if everybody follows a standard.
ATTENTION: We skiptype annotations from validation.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.
'...' is preceded with whitespace. Open
public static void enforceAnyRole(@Nonnull Message model, @Nonnull DatapointType ...types) throws InvalidModelType {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there is no whitespace before a token. Morespecifically, it checks that it is not preceded with whitespace, or(if linebreaks are allowed) all characters on the line before arewhitespace. To allow linebreaks before a token, set propertyallowLineBreaks
to true
. No check occursbefore semi-colons in empty for loop initializers or conditions.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.