TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
 
TIOBE - Java Coding Standard
Search

Coding Rules

Rule Kind
Checked automatically with code checker
Severity Level


NameCheckedSynopsis
Basic1 Checked automatically with code checker Avoid empty catch blocks
Basic2 Checked automatically with code checker Avoid empty 'if' statements
Basic3 Checked automatically with code checker Avoid empty 'while' statements
Basic4 Checked automatically with code checker Avoid empty try blocks
Basic5 Checked automatically with code checker Avoid empty finally blocks
Basic6 Checked automatically with code checker Avoid empty switch statements
Basic7 Checked automatically with code checker Avoid modifying an outer loop incrementer in an inner loop for update expression
Basic8 Checked automatically with code checker This for loop could be simplified to a while loop
Basic9 Checked automatically with code checker Avoid unnecessary temporaries when converting primitives to Strings
Basic10 Checked automatically with code checker Ensure you override both equals() and hashCode()
Basic11 Checked automatically with code checker Double checked locking is not thread safe in Java
Basic12 Checked automatically with code checker Avoid returning from a finally block
Basic13 Checked automatically with code checker Avoid empty synchronized blocks
Basic14 Checked automatically with code checker Avoid unnecessary return statements
Basic15 Checked automatically with code checker Empty static initializer was found
Basic16 Checked automatically with code checker Do not use 'if' statements that are always true or always false
Basic17 Checked automatically with code checker An empty statement (semicolon) not part of a loop
Basic18 Checked automatically with code checker Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE
Basic19 Checked automatically with code checker Unnecessary final modifier in final class
Basic20 Checked automatically with code checker These nested if statements could be combined
Basic21 Checked automatically with code checker Overriding method merely calls super
Basic22 Checked automatically with code checker This usage of the Collection.toArray() method will throw a ClassCastException
Basic23 Checked automatically with code checker Avoid creating BigDecimal with a decimal (float/double) literal. Use a String literal
Basic24 Checked automatically with code checker An operation on an Immutable object (BigDecimal or BigInteger) won't change the object itself
Basic25 Checked automatically with code checker The null check here is misplaced; if the variable is null there'll be a NullPointerException
Basic26 Checked automatically with code checker Invoke equals() on the object you've already ensured is not null
Basic27 Checked automatically with code checker Avoid using ThreadGroup; it is not thread safe
Basic28 Checked automatically with code checker Method call on object which may be null
Basic29 Checked automatically with code checker Don't create instances of already existing BigInteger and BigDecimal (ZERO, ONE, TEN)
Basic30 Checked automatically with code checker Do not start a literal by 0 unless it's an octal value
Basic100 Checked automatically with code checker Each variable should have an initializer.
Basic101 Checked automatically with code checker Use standard brace style.
Basic102 Checked automatically with code checker Avoid implicit allocation of objects
CloneImplementation1 Checked automatically with code checker Object clone() should be implemented with super.clone()
CloneImplementation2 Checked automatically with code checker clone() method should throw CloneNotSupportedException
CloneImplementation3 Checked automatically with code checker clone() method should be implemented only if implementing Cloneable interface
CodeSize1 Checked automatically with code checker Avoid complex methods
CodeSize2 Checked automatically with code checker Avoid really long methods
CodeSize3 Checked automatically with code checker Avoid really long parameter lists
CodeSize4 Checked automatically with code checker Avoid really long classes
CodeSize5 Checked automatically with code checker Avoid complex code
CodeSize6 Checked automatically with code checker This class has too many public methods and attributes
CodeSize7 Checked automatically with code checker Too many fields
CodeSize8 Checked automatically with code checker Avoid large methods
CodeSize9 Checked automatically with code checker Avoid long type definitions
CodeSize10 Checked automatically with code checker Avoid complex constructors
Comments100 Checked automatically with code checker Every file should have a copyright statement at the top.
Comments101 Checked automatically with code checker Use standard Java annotations.
Comments102 Checked automatically with code checker Use one annotation per line.
Comments103 Checked automatically with code checker Use TODO comments.
Comments104 Checked automatically with code checker Each class should be preceded by JavaDoc comments.
Controversial1 Checked automatically with code checker Avoid unnecessary constructors - the compiler will generate these for you
Controversial2 Checked automatically with code checker Assigning an Object to null is a code smell. Consider refactoring
Controversial3 Checked automatically with code checker A method should have only one exit point, and that should be the last statement in the method
Controversial4 Checked automatically with code checker Avoid modifiers which are implied by the context
Controversial5 Checked automatically with code checker Avoid assignments in operands
Controversial6 Checked automatically with code checker Each class should declare at least one constructor
Controversial7 Checked automatically with code checker Avoid importing anything from the 'sun.*' packages
Controversial8 Checked automatically with code checker Suspicious decimal characters following octal escape in string literal
Controversial9 Checked automatically with code checker It is a good practice to call super() in a constructor
Controversial10 Checked automatically with code checker This statement may have some unnecessary parentheses
Controversial11 Checked automatically with code checker If a field is only used by one method, consider making it a local variable
Controversial12 Checked automatically with code checker Use explicit scoping instead of the default package private level
Controversial12 Checked automatically with code checker Use explicit scoping instead of the default package private level
Controversial13 Checked automatically with code checker Use bitwise inversion to invert boolean values
Controversial14 Checked automatically with code checker Make sure variable assignment has been performed correctly
Coupling1 Checked automatically with code checker High amount of different objects as members denotes a high coupling
Coupling2 Checked automatically with code checker A high number of imports can indicate a high degree of coupling within an object
Coupling3 Checked automatically with code checker Avoid using implementation types; use the interface instead
Design1 Checked automatically with code checker Classes with only static methods should have a private constructor
Design2 Checked automatically with code checker Avoid unnecessary if..then..else statements when returning a boolean
Design3 Checked automatically with code checker Avoid unnecessary comparisons in boolean expressions
Design4 Switch statements should have a default label
Design5 Checked automatically with code checker Deeply nested if..then statements are hard to read
Design6 Checked automatically with code checker Avoid reassigning parameters
Design7 Checked automatically with code checker A high ratio of statements to labels in a switch statement. Consider refactoring
Design8 Checked automatically with code checker Don't call overridable methods during object construction
Design9 Checked automatically with code checker Avoid instantiation through private constructors from outside of the constructor's class
Design10 Checked automatically with code checker This final field could be made static
Design11 Checked automatically with code checker Ensure that resources are closed after use
Design12 Checked automatically with code checker Non-static initializers are confusing
Design13 Checked automatically with code checker The default label should be the last label in a switch statement
Design14 Checked automatically with code checker A non-case label was present in a switch statement
Design15 Checked automatically with code checker This call to Collection.toArray() may be optimizable
Design16 Checked automatically with code checker Avoid equality comparisons with Double.NaN
Design17 Checked automatically with code checker Avoid using equals() to compare against null
Design18 Checked automatically with code checker Avoid if (x != y) ..; else ..;
Design19 Checked automatically with code checker Avoid instantiating an object just to call getClass() on it; use the .class public member instead
Design20 Checked automatically with code checker Avoid idempotent operations (like assigning a variable to itself)
Design21 Checked automatically with code checker When instantiating a SimpleDateFormat object, specify a Locale
Design22 Checked automatically with code checker Declare private fields final, if possible
Design23 Checked automatically with code checker When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Design24 Checked automatically with code checker Avoid protected fields in a final class. Change to private or package access
Design25 Checked automatically with code checker Possible unsafe assignment to a non-final static field in a constructor
Design26 Checked automatically with code checker Class cannot be instantiated and does not provide any static methods or fields
Design27 Checked automatically with code checker Use block level rather than method level synchronization
Design28 Checked automatically with code checker A switch statement does not contain a break
Design29 Checked automatically with code checker Call Thread.notifyAll() rather than Thread.notify()
Design30 Checked automatically with code checker An instanceof check is being performed on the caught exception. Create a separate catch clause for this exception type
Design31 Checked automatically with code checker This abstract class does not have any abstract methods
Design32 Checked automatically with code checker No need to check for null before an instanceof
Design33 Use equals() to compare object references
Design34 Checked automatically with code checker Position literals first in String comparisons
Design35 Checked automatically with code checker Consider simply returning values instead of storing it in a local variable
Design36 Checked automatically with code checker Singleton is not thread safe
Design37 Checked automatically with code checker Document empty method
Design38 Checked automatically with code checker Document empty constructor
Design39 Checked automatically with code checker An Interface should be used only to model a behaviour; consider converting this to a class
Design40 Checked automatically with code checker Static DateFormatter objects should be accessed in a synchronized manner
Design41 Checked automatically with code checker Caught exception is rethrown, original stack trace may be lost
Design42 Checked automatically with code checker Substitute calls to size() == 0 (or size() != 0) with calls to isEmpty()
Design43 Checked automatically with code checker Declare members privately
Design44 Checked automatically with code checker Never initialize a final field to null
Design100 Checked automatically with code checker The scope of local variables should be kept to a minimum.
Finalizer1 Checked automatically with code checker Avoid empty finalize methods
Finalizer2 Checked automatically with code checker Finalize should do something besides just calling super.finalize()
Finalizer3 Checked automatically with code checker Finalize methods should not be overloaded
Finalizer4 Checked automatically with code checker Last statement in finalize method should be a call to super.finalize()
Finalizer5 Checked automatically with code checker If you override finalize(), make it protected
Finalizer6 Checked automatically with code checker Avoid calling finalize() explicitly
Finalizer100 Checked automatically with code checker Don't use finalizers.
Import101 Checked automatically with code checker Order import statements.
ImportStatement1 Checked automatically with code checker Avoid duplicate imports
ImportStatement2 Checked automatically with code checker Avoid importing anything from the package 'java.lang'
ImportStatement3 Checked automatically with code checker Avoid unused imports
ImportStatement4 Checked automatically with code checker No need to import a type that lives in the same package
ImportStatement100 Checked automatically with code checker Fully qualify imports.
ImportStatement101 Checked automatically with code checker Order Import Statements.
JUnit1 Checked automatically with code checker You have a suite() method that is not both public and static, so JUnit won't call it to get your TestSuite. Is that what you wanted to do?
JUnit2 Checked automatically with code checker You may have misspelled a JUnit framework method (setUp or tearDown)
JUnit3 Checked automatically with code checker JUnit assertions should include a message
JUnit4 Checked automatically with code checker JUnit tests should include assert() or fail()
JUnit5 Checked automatically with code checker This class name ends with 'Test' but contains no test cases
JUnit6 Checked automatically with code checker assertTrue(true) or similar statements are unnecessary
JUnit7 Checked automatically with code checker Use assertEquals(x, y) instead of assertTrue(x.equals(y))
JUnit8 Checked automatically with code checker Use assertSame(x, y) instead of assertTrue(x==y), or assertNotSame(x,y) vs assertFalse(x==y)
JUnit9 Checked automatically with code checker Use assertNull(x) instead of assertTrue(x==null), or assertNotNull(x) vs assertFalse(x==null)
JUnit10 Checked automatically with code checker assertTrue(!expr) can be replaced by assertFalse(expr)
JavaLogging1 Checked automatically with code checker Class contains more than one logger.
JavaLogging2 Checked automatically with code checker The Logger variable declaration does not contain the static and final modifiers
JavaLogging3 Checked automatically with code checker System.out.print is used
JavaLogging4 Checked automatically with code checker Avoid printStackTrace(); use a logger call instead.
Naming1 Checked automatically with code checker Avoid variables with short names
Naming2 Checked automatically with code checker Avoid excessively long variable names
Naming3 Checked automatically with code checker Avoid using short method names
Naming4 Checked automatically with code checker Use naming conventions for variables
Naming5 Checked automatically with code checker Method name does not begin with a lower case character
Naming6 Checked automatically with code checker Class names should begin with an uppercase character
Naming7 Checked automatically with code checker Abstract classes should be named 'AbstractXXX'
Naming8 Checked automatically with code checker Avoid using dollar signs in variable/method/class/interface names
Naming9 Checked automatically with code checker Classes should not have non-constructor methods with the same name as the class
Naming10 Checked automatically with code checker The method name and return type are suspiciously close to hashCode()
Naming11 Checked automatically with code checker The field name indicates a constant but its modifiers do not
Naming12 Checked automatically with code checker The method name and parameter number are suspiciously close to equals(Object)
Naming13 Checked automatically with code checker It is somewhat confusing to have a field name matching the declaring class name
Naming14 Checked automatically with code checker It is somewhat confusing to have a field name with the same name as a method
Naming15 Checked automatically with code checker Don't define methods with the same name as the class name
Naming16 Checked automatically with code checker All classes and interfaces must belong to a named package
Naming17 Checked automatically with code checker Package name contains upper case characters
Naming18 Checked automatically with code checker Avoid naming non-fields with a member-like prefix
Naming101 Checked automatically with code checker Treat acronyms as words
Optimization1 Checked automatically with code checker Local variables assigned only once can be declared final
Optimization2 Checked automatically with code checker A method argument that is never assigned can be declared final
Optimization3 Checked automatically with code checker Avoid instantiating new objects inside loops
Optimization4 Checked automatically with code checker Use ArrayList instead of Vector
Optimization5 Checked automatically with code checker This call to String.startsWith can be rewritten using String.charAt(0)
Optimization6 Checked automatically with code checker Prefer StringBuffer over += for concatenating strings
Optimization7 Checked automatically with code checker Use asList instead of tight loops
Optimization8 Checked automatically with code checker System.arrayCopy is more efficient
Optimization9 Checked automatically with code checker Unnecessary wrapper object creation
Optimization100 Checked automatically with code checker Declare JAXBcontext variables as static.
SecurityCodeGuidelines1 Checked automatically with code checker Don't return an internal array directly.
SecurityCodeGuidelines2 Checked automatically with code checker User-supplied arrays should be copied before use
StrictException1 Checked automatically with code checker A catch statement should never catch throwable since it includes errors
StrictException2 Checked automatically with code checker A method/constructor shouldn't explicitly throw java.lang.Exception
StrictException3 Checked automatically with code checker Avoid using exceptions as flow control
StrictException4 Checked automatically with code checker Avoid catching NullPointerException; consider removing the cause of the NPE
StrictException5 Checked automatically with code checker Avoid throwing raw exception types
StrictException6 Checked automatically with code checker Avoid throwing null pointer exceptions
StrictException7 Checked automatically with code checker A catch statement that catches an exception only to rethrow it should be avoided
StrictException100 Checked automatically with code checker Don't ignore exceptions.
StrictException101 Checked automatically with code checker Don't catch generic exceptions.
StringandStringBuffer1 Checked automatically with code checker Don't use duplicate String literals; use constants instead
StringandStringBuffer2 Checked automatically with code checker Avoid instantiating String objects; this is usually unnecessary
StringandStringBuffer3 Checked automatically with code checker Avoid calling toString() on String objects; this is unnecessary
StringandStringBuffer4 Checked automatically with code checker Avoid concatenating nonliterals in a StringBuffer constructor or append()
StringandStringBuffer5 Checked automatically with code checker Using equalsIgnoreCase() is cleaner than using toUpperCase/toLowerCase().equals()
StringandStringBuffer6 Checked automatically with code checker This is an inefficient use of StringBuffer.toString; call StringBuffer.length instead
StringandStringBuffer7 Checked automatically with code checker Avoid appending characters as strings in StringBuffer.append
StringandStringBuffer8 Checked automatically with code checker Combine StringBuffer.append calls, if possible
StringandStringBuffer9 Checked automatically with code checker String.indexOf(char) is faster than String.indexOf(String)
StringandStringBuffer10 Checked automatically with code checker String.trim().length()==0 is an inefficient way to validate an empty String
StringandStringBuffer11 Checked automatically with code checker Initialize objects of StringBuffer with a proper size
StringandStringBuffer12 Checked automatically with code checker No need to call String.valueOf to append to a string
StringandStringBuffer13 Checked automatically with code checker Do not instantiate a StringBuffer with a char
Style100 Checked automatically with code checker Don't use tabs.
Style101 Checked automatically with code checker Indent properly.
Style102 Checked automatically with code checker Limit line length
Style102 Checked automatically with code checker Limit line length.
TypeResolution1 Checked automatically with code checker Avoid using implementation types; use the interface instead
TypeResolution2 Checked automatically with code checker clone() method should be implemented only if implementing Cloneable interface
UnusedCode1 Checked automatically with code checker Avoid unused private fields
UnusedCode2 Checked automatically with code checker Avoid unused local variables
UnusedCode3 Checked automatically with code checker Avoid unused private methods
UnusedCode4 Checked automatically with code checker Avoid unused {0} parameters