Guides / Code review checklist

Java code review checklist: what to check in a Java PR

A Java code review checklist adds Java’s own traps to the usual checks: a null where the contract promises none, Optional.get() on an empty value, equals without hashCode, and state shared between threads. Each comes from a real Keycloak pull request.

The checks every language shares are on the code review checklist; this page is the Java layer, built from the 25 known issues in 10 Keycloak pull requests in our benchmark.[1]

Checked

What should a Java code review check?

A Java code review should check 14 things in four groups: null and contracts, equality, resources and threads, and data and security. Formatting is left to Checkstyle, so none of the 14 is about style.

Null and contracts

  1. Null contracts holdA method whose Javadoc says it never returns null must not. Keycloak’s getSubGroupsCount() returned null in a fix meant to stop a NullPointerException.
    IonWarp Code Review checks this
  2. Optional is unwrapped safelyOptional.get() throws when empty, and its own Javadoc prefers orElseThrow().[2] Keycloak called get() on recovery codes without a check.
    IonWarp Code Review checks this
  3. Argument checks check the right argumentKeycloak’s AccessTokenContext ran Objects.requireNonNull on grantType twice and never on rawTokenId.
    IonWarp Code Review checks this
  4. Wrappers call the delegate, not themselvesA Keycloak caching provider called session.identityProviders().getById(), which is itself, instead of its delegate: endless recursion.
    IonWarp Code Review checks this

Equality and values

  1. equals and hashCode change togetherEqual objects must have equal hash codes,[3] or HashMap and HashSet lose entries.
    IonWarp Code Review checks this
  2. BigDecimal is compared with compareToequals counts scale, so 2.0 is not equal to 2.00.[4]
    IonWarp Code Review checks this

Resources, errors and threads

  1. Resources close in try-with-resourcesStreams, connections and files close even when an exception is thrown.[5]
    IonWarp Code Review checks this
  2. Exceptions are specific and loggedCatch the exception you expect, not RuntimeException, and never swallow one without a log line.
    IonWarp Log & Errors checks this
  3. Library code never exits the JVMKeycloak’s change called picocli.exit(), which calls System.exit(), from inside a command.
    IonWarp Code Review checks this
  4. Shared state is thread-safeSimpleDateFormat is not synchronized;[6] use DateTimeFormatter. Check-then-act on a shared map needs computeIfAbsent or a lock.
    IonWarp Code Review checks this
  5. Concurrent tests wait for their threadsA Keycloak test flipped a flag and asserted before its reader thread finished, so it could pass by luck.
    IonWarp Code Review checks this

Data, flags and security

  1. No query runs inside a loopJPA lazy loading inside a loop is one query per row; fetch the relation with the list, and page every list.
    IonWarp API Performance checks this
  2. Feature flags guard features, not cleanupKeycloak guarded the listener that cleans up permissions for removed roles, clients and groups with the V1 flag; with only V2 on, they were left orphaned.[1]
    IonWarp Code Review checks this
  3. SQL takes parametersUse PreparedStatement parameters or JPA named parameters, never concatenated strings.[7]
    IonWarp Security Review checks this

Which Java bugs reach real pull requests?

The Java bugs that reach real pull requests are broken null contracts, wrong arguments and thread races: the answer key for 10 Keycloak pull requests lists 25 issues a reviewer should catch, and these eight show the patterns.[1]

  1. Critical · Logic · Keycloak PR 37634

    The fourth Objects.requireNonNull checks grantType again, so a null rawTokenId passes.

    The check: Argument checks check the right argument

  2. Critical · Logic · Keycloak PR 32918

    The cache calls session.identityProviders().getById() instead of its delegate and re-enters itself.

    The check: Wrappers call the delegate, not themselves

  3. Critical · API contract · Keycloak PR 40940

    getSubGroupsCount() returns null though the GroupModel Javadoc says it never does.

    The check: Null contracts hold

  4. Medium · Logic · Keycloak PR 38446

    Optional.get() on the recovery codes credential with no isPresent() check.

    The check: Optional is unwrapped safely

  5. High · Logic · Keycloak PR 36880

    The cleanup listener checks the V1 flag, so with only V2 on, permissions for removed objects stay behind.

    The check: Feature flags guard features, not cleanup

  6. Medium · Logic · Keycloak PR 36882

    picocli.exit() calls System.exit() directly from a command.

    The check: Library code never exits the JVM

  7. Medium · Concurrency · Keycloak PR 40940

    The test asserts before the reader thread finishes, so it can miss the exception it is for.

    The check: Concurrent tests wait for their threads

  8. Low · Logic · Keycloak PR 37634

    A test catches RuntimeException where the code throws IllegalArgumentException, so it passes for the wrong reason.

    The check: Exceptions are specific and logged

How many Java bugs do AI code reviewers catch?

AI code reviewers caught at most 15 of the 25 known Java issues in 10 Keycloak pull requests: CodeRabbit caught the most, and IonWarp caught 11. None caught them all, so the checklist stays with a person.[8][9]

Known Java issues each AI reviewer caught
ReviewerCaught (Keycloak)ShareF1, all 50 PRsFalse alarms, all 50 PRs
CodeRabbitCaught: 15 of 25Share: 60%F1, all 50 PRs: 42.1%False alarms: 194
Qodo v2Caught: 14 of 25Share: 56%F1, all 50 PRs: 58.5%False alarms: 79
Cursor BugbotCaught: 12 of 25Share: 48%F1, all 50 PRs: 51.4%False alarms: 56
IonWarp · DeepSeek V4.1 FlashCaught: 11 of 25Share: 44%F1, all 50 PRs: 49.2%False alarms: 78
Greptile v4.1Caught: 10 of 25Share: 40%F1, all 50 PRs: 51.1%False alarms: 78

Caught means the judge matched a reviewer’s comment to a known issue; false alarms are comments that matched none, over all 50 pull requests. Every row and PR is on the Code Review benchmark.

Which tools automate a Java code review?

Checkstyle, PMD, SpotBugs and Error Prone cover style and the bug patterns a compiler can see, so the reviewer spends the time on contracts, threads and data.

Java review tools and the checks they cover
ToolWhat it checksChecklist line
CheckstyleWhat it checks: Style rules, such as the Google Java Style Guide[10][11]Checklist line: None: style is off the list
PMDWhat it checks: Common flaws such as unused variables and empty catch blocks[12]Checklist line: Exceptions
SpotBugsWhat it checks: Static analysis for bugs in Java code[13]Checklist line: equals and hashCode, null
Error ProneWhat it checks: Bug patterns, as compiler errors[14]Checklist line: Null, Optional, equality
IonWarpWhat it checks: Logic, callers and missing changes on each pull requestChecklist line: Contracts, delegates, flags, threads
The IonWarp app’s Bugs screen in the sample Acme workspace: 16 bugs caught on pull requests, 1 escaped, 3 issues open
What the IonWarp app showsThe Bugs screen, in the sample workspace: each bug its agents caught on a pull request, next to the ones that got past.

Is there a Java code review checklist template?

Yes, a Java code review checklist template is below: paste it into .github/pull_request_template.md under the general checklist.[15]

## Java review
- [ ] Null contracts hold; Javadoc matches
- [ ] Optional unwrapped with orElseThrow / orElse
- [ ] requireNonNull checks the right argument
- [ ] Wrappers call the delegate, not themselves
- [ ] equals and hashCode change together
- [ ] BigDecimal compared with compareTo
- [ ] Resources in try-with-resources
- [ ] Specific exceptions, logged
- [ ] No System.exit in library code
- [ ] Shared state thread-safe; no SimpleDateFormat across threads
- [ ] Concurrent tests join their threads
- [ ] No query in a loop; lists are paged
- [ ] Feature flags don't guard cleanup
- [ ] SQL uses parameters

FAQ

Quick answers

What is a Java code review?

A second engineer reading a Java change before it merges, usually as a pull request, for bugs, broken contracts, thread safety, resource leaks and security, with style left to tools such as Checkstyle.

What should I check in a Java code review?

Null contracts, Optional.get() on an empty value, argument checks on the right argument, equals with hashCode, BigDecimal compared with compareTo, resources in try-with-resources, specific exceptions, thread-safe shared state, queries in loops, and SQL parameters.

What are the best Java code review tools?

Checkstyle for style, PMD and SpotBugs for common flaws, Error Prone for bug patterns at compile time, and an AI reviewer for logic, callers and missing changes. A person still approves.

What are Java code review best practices?

Keep the pull request small, leave style to Checkstyle, read the Javadoc of every method the change touches, and check threads and nulls by hand: they are where Keycloak’s known bugs sat.

Should a Java code review check Javadoc?

Yes. A changed return value or a new null must change the Javadoc too; Keycloak’s known issues include Javadoc that no longer matched the code.

Is there a Java code review checklist on GitHub?

Copy the template on this page into .github/pull_request_template.md, and GitHub shows it on every new pull request.

More checklists

More checklists

Get null contracts and threads checked on every PR.

Get started

See pricing

By , Co-founder, IonWarp. Published .

Co-founder of Segment (acquired by Twilio, 2020). Builds IonWarp at Winding AI, Inc. See something wrong? Send us a correction.