Java Code Review Guidelines¶
Comprehensive checklist for reviewing Java code — formatting, naming, exception handling, collections, null safety, performance, and best practices.
1. Variable & Constant Management¶
String & Constant Declaration¶
-
Make string/global/instance variables
finalunless they need to be reassigned -
Declare common constants in a centralized Constants class
-
Reuse constants for repeated values (table names, column names, separators)
-
Use enums for status/type values
Variable Naming Conventions¶
-
Use clear, meaningful names — avoid single-letter variables (except loop counters)
-
Avoid overly long variable names
-
Boolean methods should start with
isorhas -
Getter methods must always return a value
2. Method Design¶
Method Purpose & Signature¶
-
Each method should do ONE thing only (Single Responsibility)
-
Limit method parameters to 6-7 maximum — use object parameters for more
-
Keep heavy/large objects as the last parameter
-
Limit statements per method to 50-70 lines — break into smaller methods
Return Statements & Logic¶
-
Avoid multiple return statements — use single return or guard clauses
// ❌ Bad - multiple returns scattered public boolean validate(Data data) { if (data == null) return false; if (data.isEmpty()) return false; if (!data.isValid()) return false; return true; } // ✅ Good - single return public boolean validate(Data data) { if (data == null || data.isEmpty() || !data.isValid()) return false; return true; } // ✅ Also Good - guard clauses public boolean validate(Data data) { if (data == null) return false; if (data.isEmpty()) return false; return data.isValid(); } -
Segregate logic from return statement
3. Exception Handling¶
Exception Declaration & Propagation¶
-
Use
throwsin method signature — don't wrap with unnecessary try-catch -
Throw specific, relevant exceptions — not generic
Exception -
For
throwsmethod, use naming conventionthrow[ExceptionType][MethodName]
Logging Exceptions¶
-
Log meaningful exception information — use
getMessage()or detail, not raw exception// ❌ Bad - too verbose or vague LOGGER.error(exception); // Prints whole stack LOGGER.error("Error"); // No details // ✅ Good - clear message + exception for context LOGGER.error("Failed to process customer {}: {}", customerId, exception.getMessage(), exception); // ✅ Also Good - message-only when appropriate LOGGER.error("Database connection failed", exception); -
Don't suppress unchecked exceptions at class level
-
Use appropriate log levels in switch/default cases
4. Null & Empty Checks¶
Null Safety¶
-
Use
Object.nonNull()for null checks -
Avoid double negatives in null checks
-
Multiple null checks on same variable — use single check
-
Avoid unnecessary null checks when guaranteed by framework
Collection Checks¶
-
Use Spring's
CollectionUtilsinstead of manual checks -
Use
StringUtils.isAllEmpty()for multiple string checks -
Check before calling trim() or strip()
5. Collections & Streams¶
Stream API Best Practices¶
-
Use Java 8+ Streams instead of traditional loops when possible
-
Use predicates for complex filter conditions
// ❌ Bad - complex condition in filter List<Data> result = dataList.stream() .filter(x -> x.getType() != null && x.getType().equals("A") && x.getStatus() != null && x.getStatus().equals("ACTIVE") && x.getDate() != null && x.getDate().equals(targetDate)) .collect(Collectors.toList()); // ✅ Good - separate predicate Predicate<Data> isValidData = d -> d.getType().equals("A") && d.getStatus().equals("ACTIVE") && d.getDate().equals(targetDate); List<Data> result = dataList.stream() .filter(isValidData) .collect(Collectors.toList()); -
Use
collect()overreduce()for accumulation -
Use
IntStream.range()for numeric ranges
Collection Initialization¶
-
Use
List.of()instead ofnew ArrayList<>()for immutable lists -
Use pattern matching for instanceof + casting (Java 16+)
6. Code Formatting & Style¶
Braces & Structure¶
-
Opening brace
{at end of line, closing brace}on new line -
Always use braces, even for single-statement blocks
-
Avoid unnecessary nested blocks — keep nesting to 3 levels max
-
Use early returns to avoid else blocks
-
Leave a blank line after logical groups of statements
Logical Operators & Readability¶
-
Use parentheses for complex conditions — especially with multiple
|| -
When using
||, put the object check before method calls -
Use
.matches()instead of multiple||operators
7. Performance & Optimization¶
Database & Caching¶
-
Minimize CICS calls — use multi-ref features when available
-
Use SSA qualifications for filtering — don't filter in Java code
-
Use StringBuilder instead of String concatenation in loops
-
Reuse common utility methods — don't duplicate logic
Assignment & Type Handling¶
-
Avoid unnecessary assignments and casting
-
Use var for type inference (Java 10+) when type is obvious
8. Spring & Framework-Specific¶
Dependency Injection & Components¶
-
Use
@Componenton helper classes — enables DI and Spring management -
Annotate DataHelper with
@Component— for Spring management and lifecycle -
Use
@PostConstructfor initialization
Method Parameter Handling¶
- For PacketProcessor, don't set PacketID again — base method already does it
9. Miscellaneous¶
Avoiding Anti-Patterns¶
-
Don't use
@Deprecatedin production code — remove deprecated code -
Don't use
HttpServletRequest.getRequestSessionId()— use Spring Security -
Don't commit files from
bin/folder — add to.gitignore - Don't commit files with no changes — review diffs before staging
Comments & Documentation¶
-
Avoid redundant comments — code should be self-documenting
-
No comments for removed code — use git history
10. Enum & Type Safety¶
Enum Design¶
- Make enum fields
privateand set via constructor// ❌ Bad - public fields, security risk public enum Status { ACTIVE("A"), INACTIVE("I"); public String code; } // ✅ Good - private fields, immutable public enum Status { ACTIVE("A"), INACTIVE("I"); private final String code; Status(String code) { this.code = code; } public String getCode() { return code; } }
Replace Switch with Enum¶
- Use Enum methods instead of switch statements when possible
Checklist for Code Reviews¶
Before Review¶
- [ ] Understand the PR intent and requirements
- [ ] Check if related tests are included
- [ ] Look for TODO/FIXME comments (should be in issues, not code)
Critical Issues¶
- [ ] All methods throw exceptions properly (no silent failures)
- [ ] Exception handling uses specific exceptions, not generic
Exception - [ ] Null checks are in place for external input
- [ ] No SQL injection or security vulnerabilities
- [ ] No hardcoded credentials or sensitive data
Code Quality¶
- [ ] Methods are focused and do one thing
- [ ] No method exceeds 50-70 statements
- [ ] Variable names are clear and meaningful
- [ ] No commented-out code
- [ ] No unnecessary imports or variables
- [ ] Logging is appropriate and non-verbose
Performance¶
- [ ] No N+1 database queries
- [ ] Collections properly sized/initialized
- [ ] Streams used correctly (lazy evaluation)
- [ ] No unnecessary string concatenation in loops
- [ ] CICS calls are minimized
Style & Formatting¶
- [ ] Braces formatted correctly (opening at end of line)
- [ ] No deeply nested blocks (max 3 levels)
- [ ] Blank lines separate logical sections
- [ ] Complex conditions have parentheses for clarity
- [ ] Consistent with team style guide
Testing¶
- [ ] All new code has tests
- [ ] Edge cases covered (null, empty, boundary values)
- [ ] No test files modified unless necessary
- [ ] Test data is realistic and documented
Source & Attribution¶
Internal Company Standards¶
These guidelines are based on enterprise Java code review best practices established across multiple projects and teams: - TSYS Enterprise Mainframe Framework (EMF) — multi-year accumulated knowledge - NACH (National ACH) XML Provider projects — payment processing standards - IRL, NOA, INTCH packet processors — production-critical systems - Internal code review PRs and technical discussions
Key contributors: Architecture leads, senior engineers, and tech reviewers across EMF ecosystem
External References & Best Practices¶
- Java Code Style: Google Java Style Guide
- Clean Code: Robert C. Martin's "Clean Code" — method design, naming conventions
- Effective Java: Joshua Bloch — null safety, collections, generics
- Design Patterns: Gang of Four design patterns — enum patterns, immutability
- Spring Framework: Spring Best Practices — DI, component lifecycle
- Java 8+ Features: Streams, lambda expressions, Optional patterns
- Performance Tuning: String concatenation, collection initialization best practices
Standard Documentation¶
- Oracle Java Language Specification
- Maven & Gradle conventions
- Spring Framework documentation
- JUnit & testing best practices