1. Test methods must contain at least one assertion.
  2. States used only once in a class should be injected directly into the method for cleanliness.
  3. Do not define two class-level states with the same name differing only by letter case.
  4. Avoid passing configuration values into static fields of a class.
  5. Only import necessary classes instead of using wildcard imports (e.g., import com.example.*).
  6. A method should not have more than 10 logic branches (Cyclomatic Complexity ≤ 10).
  7. Reusable values should be assigned to variables instead of being repeated.
  8. Avoid nesting more than 3 levels of if, for, while, switch, or try.
  9. Classes used for declaring constants should have a private constructor.
  10. States not injected from outside should be declared as static.
  11. States initialized in place must be declared as final.
  12. Local variables should be declared close to their usage, not prematurely.
  13. Methods unrelated to injected dependencies should be declared static.
  14. Do not use System.out; use a proper logger instead.
  15. When comparing strings, place the constant on the left side (e.g., "abc".equals(variable)) to avoid NullPointerException.
  16. Catch blocks should separate unrelated exceptions or group them explicitly using A | B | C e; avoid catching related types together.
  17. Avoid calling String.join() or similar methods directly within conditions; declare the result beforehand.
  18. Do not use @SuppressWarnings to ignore compiler warnings.
  19. Every caught exception should either be logged or rethrown to preserve the stack trace.
  20. For dependency injection, prefer constructor injection with final fields over @Autowired.
  21. Logging utilities or log invocations should check the appropriate log level (isDebugEnabled(), etc.) before formatting messages to avoid unnecessary processing.
  22. Object-type fields that are not injected and not initialized immediately should be set to null explicitly to indicate they are not injected.
  23. Do not mix blocking calls in non-blocking (reactive/asynchronous) contexts.

Leave a Reply

Your email address will not be published. Required fields are marked *