A small PR for Java 21 needs to be reviewed. The service runs in a single JVM process, without third-party dependencies, using only the standard library. Launch: javac --release 21 *.java && java OrderCacheDemo. Contract: OrderCache accepts order update events and stores the latest version by orderId; the snapshot() method must return a consistent snapshot of the current state without duplicate keys. No input data is required to reproduce — behavior is verified through main. In before, the code behaves correctly for single updates and the basic snapshot. In after, changes were made to speed up and simplify the cache; the review needs to find defects that cause state corruption after repeated updates and when comparing orders. Assumptions: all calls happen within one process, but updates may come from multiple threads; Order is considered identical by orderId.
Java 21, standard library only, no build tool, execution mode: javac --release 21 *.java && java OrderCacheDemo
Use line comments to explain the problem, its impact, the fix and how to test it.