Skip to content
Interview rounds

Java/Spring/JVM · Bug Squash (Java)

The transfer that would not roll back

A Spring @Transactional method throws, and the database change is not rolled back. Where is the bug?

BackendSenior10 min
Interview-style scenarioLast reviewed: Checked against official documentation

Bug Squash · Java 21, Spring Boot 3 · TransferService.javaIllustrative scenario, not a real incident

A failed transfer left the source account debited: 40.00 gone, credited to nobody

A batch job calls transferAll with the day's transfers. One of them named an account that does not exist. The transfer threw LedgerException, as it should, and the batch stopped.

The source account had already been debited, and the debit is still there. A test that reproduces it is below. No code runs in your browser: read it as you would in a review.

What the dashboards and logs show

Expected
balance of ACC-1 unchanged at 100.00
Actual
60.00: the debit was committed
Exception
LedgerException: unknown account ACC-9
Transaction manager
configured, and used elsewhere without trouble

Find the bug · scored under "Hypothesis before change"

Tap the faulty lines

The test below fails. Mark up to 3 lines you would change, then check them. There are 2. A wrong mark costs half a line.

Failing test · debitIsRolledBackWhenTheTargetAccountIsUnknown
TransferServiceTest > debitIsRolledBackWhenTheTargetAccountIsUnknown() FAILED
    org.opentest4j.AssertionFailedError:
    balance of ACC-1 after a failed transfer
    expected: <100.00> but was: <60.00>

1 test completed, 1 failed
TransferService.java

No line marked yet

Your rubric score, the model answer, the follow-up questions and the related lessons appear once you have answered the last step.