liveBook · Manning

Illegal state

As explained in Troubleshooting Java, Second Edition

An invalid state is a condition represented in system data that violates domain rules or does not make sense in the real world.

An invalid object state is data that violates a domain invariant: a rule that must remain true for the system to represent a valid business reality. The data may exist in a database while making no sense outside it. section 13.1.2

Investigate invalid states by asking which business rule failed and how the data became inconsistent:

  • Check for race conditions, delayed or out-of-order messages, retries, and eventual-consistency gaps. section 13.1.2
  • Look for missing defensive checks and partially completed operations across services or databases. section 13.1.2
  • Validate domain rules directly; logs and traces can miss inconsistencies that invariant checks expose. section 13.1.2

Concrete invalid states

A payment completes without an order, a user has a birthdate in the future, or a refund is processed before its referenced order is written. Each condition can technically exist while violating business reality. section 13.1.2

SELECT * FROM refunds r
WHERE NOT EXISTS (
  SELECT 1 FROM orders o WHERE o.id = r.order_id
);

Find refunds whose referenced orders do not exist, exposing one class of invalid state directly in stored data. section 13.1.2

How Troubleshooting Java, Second Edition covers it

How deep it goes
Defines invalid states, identifies distributed causes, and demonstrates a direct database check without detailing remediation.
Examples
Uses orphaned refunds, payments without orders, future birthdates, delayed messages, and an anti-join query.
What it assumes
Starts from business rules and basic distributed-system failure modes rather than assuming advanced implementation knowledge.
What you can do after
Diagnose invalid data by defining violated invariants and querying for records that contradict related business entities.
How it connects
Connects invalid states with domain invariants, race conditions, eventual consistency, retries, message ordering, and transactions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.