Analyses

Declare the particular checked exceptions which can be thrown by your method (es.uniovi.reflection.analyses.bloch.9.62) 

by garciarmiguel@uniovi.es

This rule detects methods that may throw a checked exception whose particular type is not explicitly declared in the throws clause (because a supertype is declared to be thrown instead). All the particular types of checked exception that may be thrown in a method must be declared in its signature.

When you catch an exception to throw a new higher-level one, make sure to set the original exception as the cause. (es.uniovi.reflection.analyses.bloch.9.61.2) 

by garciarmiguel@uniovi.es

This rule detects methods that may throw a checked exception whose particular type is not explicitly declared in the throws clause (because a supertype is declared to be thrown instead).All the particular types of checked exception that may be thrown in a method must be declared in its signature.

Adhere to generally accepted naming conventions (es.uniovi.reflection.analyses.bloch.8.56.2) 

by garciarmiguel@uniovi.es

This rule detects packages that start with 'java' or 'javax' reserved names, have no hierarchical structure with component names separated by '.', or do not follow the lowercase convention. It also detects when the default package contains any type declaration.

Adhere to generally accepted naming conventions (es.uniovi.reflection.analyses.bloch.8.56.1) 

by garciarmiguel@uniovi.es

This rule detects types whose names do not follow the CamelCase convention. It also checks that methods, non-final local variable, parameters and fields follow the camelCase convention, excepting static final (constant) fields that must follow the SNAKE_CASE convention.

Beware the performance of String concatenation (es.uniovi.reflection.analyses.bloch.8.51) 

by garciarmiguel@uniovi.es

This rule detects when the operators + or += are used to concatenate any String inside a loop. This is risky since this operation already takes quadratic time and StringBuilder class must be used instead.

Minimize the scope of local variables (es.uniovi.reflection.analyses.bloch.8.45) 

by garciarmiguel@uniovi.es

This rule detects both initialized and non-initialized local variable declarations which are not used in the following statement of the program. The rule recommends moving these declarations just before the statements in which they are used for the first time. Variables declared as try-resources, catch parameters, for-each or traditional for initializations are not considered. Also, when the first use of the variable is inside an inner scope, the recommendation will be to move it just before if the variable is only used in that inner scope or else move it just before entering the inner scope. Finally, we also allow some statements between the declaration and its first use as long as these statements are declarations of other variables first used in the very same statement.

For parameter types, favor interfaces over classes (es.uniovi.reflection.analyses.bloch.7.40.2) 

by garciarmiguel@uniovi.es

This rule detects parameters whose type implements an interface that can be safely used to type the parameter instead. This means that all the methods invoked by and attributes accessed on the parameter must belong to the interface type (or the Object class). If the parameter is passed as argument to some method, this method must accept the interface type as argument too. If the parameter is iterated in a for-each loop, the interface type must extend the java.lang.Iterable interface. Additionally, if the parameter is assigned to some variable, it will be checked that the type of this variable canbe safely changed to the interface type too. Also, if the parameter belongs to a method that overrides or is overridden by another method, it will not be considered. Parameters whose type is an enum or already an interface are not considered. Finally, too general interfaces such as java.io.Serializable, java.lang.Comparable, java.lang.Cloneable, java.lang.constant.Constable, java.lang.constant.ConstantDesc and java.lang.CharSequence are not recommended for the change.

Check parameters for validity (es.uniovi.reflection.analyses.bloch.7.38) 

by garciarmiguel@uniovi.es

This rule detects public/protected method or constructor definitions in public types that declare a parameter used inside, but there is no previous validity check performed on it. The rule checks parameters belonging to the unnamed module or belonging to packages explicitly exported (in the module declaration) to all modules or to a module that is not part of the project. Any use of the parameter as a condition in an if or conditional expression, as an argument in a method call, or as a selector expression in a switch will be understood as a validity check. If the parameter is assigned before its use, the check is not needed.

Consistently use the Override annotation (es.uniovi.reflection.analyses.bloch.6.36) 

by garciarmiguel@uniovi.es

This rule detects methods overriding a method from one of its supertypes, which are not tagged with the java.lang.Override annotation.

Minimize the accessibility of members (es.uniovi.reflection.analyses.bloch.4.13.2) 

by garciarmiguel@uniovi.es

This rule detects members whose access level must be reduced. More precisely, it detects public fields which are arrays or non-final declared in public types, since they must never be public. It also detects public or protected members that are declared in a type with lower access level, since they are not accessible as long as its enclosing type is not, and therefore their visibility can always be reduced. Finally, it detects package-private members that are only accessed from its compilation unit, and therefore their visibility can always be reduced to private. We do not consider fields and methods that are never used. We also do not consider methods that override or are overridden by any other method.

Minimize the accessibility of classes (es.uniovi.reflection.analyses.bloch.4.13.1) 

by garciarmiguel@uniovi.es

This rule detects public types that does not belong to the unnamed module, whose package is not declared to be exported and are only used inside its own package, in order to reduce its visibility to package-private (**Scenario 1**). Moreover, this rule also detects package-private and not exported public types that are only used by one compilation unit inside its package, in order to reduce its visibility to private, making them static inner classes (**Scenario 2**). Types that are not used by any other type in the project are not considered.

Always override hashCode when you override equals (es.uniovi.reflection.analyses.bloch.3.9) 

by garciarmiguel@uniovi.es

This rule detects classes that implement only one of the hashCode and equals methods. Both methods must be implemented to preserve the general contract for the hashCode method.

Provide public access for every field used in the toString method (es.uniovi.reflection.analyses.bloch.3.10s) 

by garciarmiguel@uniovi.es

This rule detects classes that do not provide public getters to access non-public fields which are used in the java.lang.Object:toString method. More precisely, it analyzes all the toString method body and detects fields concatenated with a String expression, calling the toString method or used as arguments when calling java.lang.StringBuilder:append, java.lang.StringBuffer:append, java.lang.Appendable:append, java.lang.String:format, java.util.Formatter:format, java.lang.String:formatted, java.lang.String:join, java.lang.String:valueOf.

Always override toString (es.uniovi.reflection.analyses.bloch.3.10) 

by garciarmiguel@uniovi.es

This rule detects types that do not implement the toString() method, but any instance of these typesexplicitly or implicitly invokes it. Types with the toString method implemented in one of its supertypes are not considered, as long as the implementation is not the default java.lang.Object:toString. Interfaces, records and abstract classes are not considered.

Enforce noninstanciability with a private constructor (es.uniovi.reflection.analyses.bloch.2.4) 

by garciarmiguel@uniovi.es

This rule detects classes that have only static members but lack a private constructor. These classes are designed to be static so, in order to prevent their instantiation, they must implement (at least) a private constructor and no other constructors with a higher access level.