Java Code Review Skill
Systematic code review checklist for Java projects.
When to Use
- User says "review this code" / "check this PR" / "code review"
- Before merging a PR
- After implementing a feature
Review Strategy
- Quick scan - Understand intent, identify scope
- Checklist pass - Go through each category below
- Summary - List findings by severity (Critical → Minor)
Output Format
Review Checklist
1. Null Safety
Check for:
Flags:
- Chained method calls without null checks
- Missing
@Nullable/@NonNullannotations on public APIs Optional.get()withoutisPresent()check- Returning
nullfrom methods that could returnOptionalor empty collection
Suggest:
- Use
Optionalfor return types that may be absent - Use
Objects.requireNonNull()for constructor/method params - Return empty collections instead of null:
Collections.emptyList()
2. Exception Handling
Check for:
Flags:
- Empty catch blocks
- Catching
ExceptionorThrowablebroadly - Losing original exception (not chaining)
- Using exceptions for flow control
- Checked exceptions leaking through API boundaries
Suggest:
- Log with context AND stack trace
- Use specific exception types
- Chain exceptions with
cause - Consider custom exceptions for domain errors
3. Collections & Streams
Check for:
Flags:
- Modifying collections during iteration
- Overusing streams for simple operations
- Assuming
Collectors.toList()returns mutable list - Not using
List.of(),Set.of(),Map.of()for immutable collections - Parallel streams without understanding implications
Suggest:
List.copyOf()for defensive copiesremoveIf()instead of iterator removal- Streams for transformations, loops for side effects
4. Concurrency
Check for:
Flags:
- Shared mutable state without synchronization
- Check-then-act patterns without atomicity
- Missing
volatileon shared variables - Synchronized on non-final objects
- Thread-unsafe lazy initialization
Suggest:
- Prefer immutable objects
- Use
java.util.concurrentclasses AtomicReference,AtomicIntegerfor simple cases- Consider
@ThreadSafe/@NotThreadSafeannotations
5. Java Idioms
equals/hashCode:
toString:
Builders:
Flags:
equalswithouthashCode- Mutable fields in
hashCode - Missing
toStringon domain objects - Constructors with > 3-4 parameters (suggest builder)
- Not using
instanceofpattern matching (Java 16+)
6. Resource Management
Check for:
Flags:
- Not using try-with-resources for
Closeable/AutoCloseable - Resources opened but not in try-with-resources
- Database connections/statements not properly closed
7. API Design
Check for:
Flags:
- Boolean parameters (prefer enums)
- Methods with > 3 parameters (consider parameter object)
- Inconsistent null handling across similar methods
- Missing validation on public API inputs
8. Performance Considerations
Check for:
Flags:
- String concatenation in loops
- Regex compilation in loops
- N+1 query patterns
- Creating objects in tight loops that could be reused
- Not using primitive streams (
IntStream,LongStream)
9. Testing Hints
Suggest tests for:
- Null inputs
- Empty collections
- Boundary values
- Exception cases
- Concurrent access (if applicable)
Severity Guidelines
Token Optimization
- Focus on changed lines (use
git diff) - Don't repeat obvious issues - group similar findings
- Reference line numbers, not full code quotes
- Skip files that are auto-generated or test fixtures


