Money bugs junior Java developers fix in banking code
Banking code is mostly ordinary Java. What makes it hard is that every number has to reconcile, and a small mistake repeats across every account. This guide covers the bugs that come up again and again around balances and dates, how to spot each one, and how to fix it so it stays fixed. The examples come from Corebank, Kadra's Spring Boot banking practice codebase.
Never store money in a double
A double can't hold most decimal fractions exactly. 0.1 + 0.2 comes out as 0.30000000000000004, and those tiny errors add up across thousands of transactions until a total is a cent off and someone has to find out why.
Banks usually store money in one of two ways: a long holding whole cents, or a BigDecimal with a fixed scale. Corebank keeps balances as long cents and interest rates as BigDecimal, which is a common split.
// Wrong: binary floating point
double total = 0.1 + 0.2; // 0.30000000000000004
// Right: whole cents in a long
long totalCents = 10 + 20; // 30
// Right: BigDecimal built from a String
BigDecimal sum = new BigDecimal("0.10").add(new BigDecimal("0.20")); // 0.30Two BigDecimal traps catch people early. new BigDecimal(0.1) copies the double's error, so build from a String or use BigDecimal.valueOf. And equals compares scale, so 2.0 and 2.00 are not equal. Use compareTo when you mean the same amount.
The available balance is not the ledger balance
The ledger balance is money that has actually moved. The available balance is what the customer can still spend: the ledger minus any holds. A hold is placed when a card payment is authorized, and it lasts until the payment settles or is released.
Corebank's CORE-701 ticket is this bug. The available balance returns the ledger balance and ignores holds, so a customer can spend money that's already promised to a merchant. A fix has to follow a hold through its whole life:
- Placing a hold lowers the available balance right away.
- Releasing a hold gives the money back.
- A settled hold has already taken the money out of the ledger, so it has to stop counting as a hold at the same moment. Count it in both places and the customer pays twice.
Use half-open date ranges for statements
Every transaction has to land on exactly one statement. If the query includes both ends of the period, a transaction posted on the boundary date shows up on two statements. That's CORE-708 in Corebank.
The standard answer is a half-open range. Include the period's first day and exclude the next period's first day, so consecutive periods meet without overlapping or leaving a gap. Here it is for a generic billing period:
// [start, nextStart): start is in, nextStart belongs to the next period
static boolean inPeriod(LocalDate day, LocalDate start, LocalDate nextStart) {
return !day.isBefore(start) && day.isBefore(nextStart);
}Test it with a transaction dated exactly on the boundary. An inclusive range gets that case wrong, and it's the one a quick fix tends to skip.
Count the real days when you accrue interest
Interest code often divides an annual rate by 12 and then by 30, as if every month had 30 days. Most months don't, and February has 28 or 29. Corebank's CORE-715 ticket asks for the actual number of days in the period, leap years included.
Let java.time do the counting instead of a constant:
long days = ChronoUnit.DAYS.between(
LocalDate.of(2028, 2, 1), LocalDate.of(2028, 3, 1)); // 29: 2028 is a leap yearThen round once, on the total for the period. Rounding every day lets the error pile up, and the interest stops matching the statement it's printed on.
Make retried payments safe
Payment requests get retried. A phone loses signal or a client times out, and the same request arrives twice. If the server processes both, the money moves twice. The usual fix is an idempotency key: the client sends a unique id with each request, and the server returns the recorded result when it sees that id again.
Kadra's Python payments service has this exact ticket, LEDG-215, and the check has to run before the balance check. The reviewer on that fix put it this way:
“placing the transfer_id in processed short-circuit before the balance check is exactly right”Practice on a banking codebase
Reading about these bugs helps. Finding one in code you didn't write teaches you more. Corebank is a Spring Boot service with the CORE tickets above planted in it. You get your own GitHub repo, fix each ticket on a branch and open a pull request. An AI teammate reviews it, and a hidden JUnit suite run by Maven decides whether it passes.
Every Corebank repo opens in GitHub Codespaces with Java 21 and Maven installed, so you don't need anything set up on your own machine.
Questions people ask
Should I use BigDecimal or long for money in Java?
Either works if you're consistent. A long of whole cents is simple and fast for balances. BigDecimal is better when you need fractions of a cent along the way, such as interest or currency conversion. Never use double or float.
Do I need to know finance to be a developer at a bank?
No. You learn the domain on the job, and a good ticket explains the rule it's about, such as holds lowering the available balance. What helps most is care with numbers and dates, and the habit of testing the edge cases.
What Java skills do banks look for in junior developers?
Most bank and fintech backends run Java with Spring Boot and a SQL database. Beyond the language, interviewers look for comfort reading existing code and writing tests for it. A reviewed pull request that fixed a real bug gives you something concrete to talk about.
Is Kadra free?
Yes, Kadra is free during beta with no credit card. After beta, Pro is planned at $12 a month or $79 a year, and the demo and your first full sprint stay free.
Try it on a real ticket
Pick a stack, fix a bug in a working codebase and get your pull request reviewed. Free during beta.
More guides
- How to get software engineering experience before your first job
- What your first code review at a software job looks like
- How to fix a bug in a codebase you didn't write
- What is a software engineering job simulator?
- Common bugs in a Node.js CMS backend, and how to fix them
- Python ETL bugs junior data engineers fix first
- Payment bugs Python developers fix in a FastAPI service
- Go REST API bugs junior developers fix first
- Booking bugs C# developers fix in ASP.NET Core
- Checkout bugs developers fix in a Next.js store
- Realtime chat bugs developers fix in TypeScript