The Share Price That Outgrew Its Integer

Easy

· Backend

Incident

SEV-2

BUG-BRKA

Priority: High · reported by market data

Time to fix: 10 min

Failing checks on the shipped build

  • a Berkshire Class A price parses exactly

    must not wrap: expected 4371310000 but got 76342704

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Nasdaq · 2021

Modelled on Nasdaq and Berkshire Hathaway (May 2021): Nasdaq's systems stored prices as an unsigned 32-bit integer with four implied decimal places, so the largest price they could represent was $429,496.7295. Berkshire Hathaway's Class A shares were approaching that figure, and Nasdaq had to upgrade its systems to a wider price field.

This project is a reconstruction in Java, which has no unsigned int. Price.parse turns a decimal price into ticks of 1/10,000 — computing in int before widening to long, so large prices wrap long before the old 32-bit ceiling.

Fix Price.parse so any realistic price is represented exactly.

Code map

class Price {
    static final int SCALE = 10000;

    static long parse(String text) {
        String[] parts = text.split("\\.");
        int whole = Integer.parseInt(parts[0]);
        int frac = 0;
        if (parts.length > 1) {
            frac = Integer.parseInt((parts[1] + "0000").substring(0, 4));
        }
        return whole * SCALE + frac;
    }

    static String format(long ticks) {
        return (ticks / SCALE) + "." + String.format("%04d", ticks % SCALE);
    }

    static long notional(long ticks, int quantity) {
        return ticks * quantity;
    }
}

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Share Price That Outgrew Its Integer — Java Bug Hunt

Modelled on Nasdaq and Berkshire Hathaway (May 2021): Nasdaq's systems stored prices as an unsigned 32-bit integer with four implied decimal places, so the…

  • Language: Java
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Overflow, Money
  • Modelled on: Nasdaq · 2021
  • Visible tests: ordinary prices parse; a Berkshire Class A price parses exactly
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-BRKA
  • Reported by: market data
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • a Berkshire Class A price parses exactly — must not wrap: expected 4371310000 but got 76342704

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Modelled on Nasdaq and Berkshire Hathaway (May 2021): Nasdaq's systems stored prices as an unsigned 32-bit integer with four implied decimal places, so the largest price they could represent was $429,496.7295. Berkshire Hathaway's Class A shares were approaching that figure, and Nasdaq had to upgrade its systems to a wider price field.

This project is a reconstruction in Java, which has no unsigned int. Price.parse turns a decimal price into ticks of 1/10,000 — computing in int before widening to long, so large prices wrap long before the old 32-bit ceiling.

Fix Price.parse so any realistic price is represented exactly.

Bug report

BUG-BRKA · Priority: High · Reported by: market data

Price.parse(text) returns the price in ticks (1 tick = 0.0001) as a long:

  • "150.25" -> 1502500, "437131" -> 4371310000
  • up to four decimal places; missing places are zeros
  • the whole-dollar part may be any non-negative value up to at least 100,000,000 — the result must never wrap

Price.format(ticks) prints whole dollars, ".", then exactly four digits. Price.notional(ticks, quantity) = ticks * quantity, as a long.

Observed: a quote of 437131.00 parsed to 76342704 ticks — a price of 7634.2704.

Logs

[quotes] BRK.A last=437131.00 ticks=76342704
[quotes] BRK.A print rejected: move of -98% vs previous close

The code as shipped

src/quotes/Price.java (editable)

class Price {
    static final int SCALE = 10000;

    static long parse(String text) {
        String[] parts = text.split("\\.");
        int whole = Integer.parseInt(parts[0]);
        int frac = 0;
        if (parts.length > 1) {
            frac = Integer.parseInt((parts[1] + "0000").substring(0, 4));
        }
        return whole * SCALE + frac;
    }

    static String format(long ticks) {
        return (ticks / SCALE) + "." + String.format("%04d", ticks % SCALE);
    }

    static long notional(long ticks, int quantity) {
        return ticks * quantity;
    }
}

Read-only context: src/quotes/LegacyFeed.java.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.