CodeSOD: The First 10,000 Note

CodeSOD: The First 10,000

Alicia inherited a suite of home-grown enterprise applications that required batch processing, but encountered a mysterious IllegalStateException caused by a query. The query in question was "select * from data_import where id > 10000", which was problematic because it checked for the existence of rows and threw an exception if any were found. The query should have been a COUNT(*) query instead of returning rows. The issue arose because the code used the ID to represent state information about the status of the record. The program updated the ID by adding 10000, inserted new data starting from ID 1, and then deleted records with IDs greater than 10000. This process was done within a single method without transactions or error handling, relying on sequential IDs to track processing failures. The process started failing when the inbound data exceeded 10,000 rows, causing the INSERTs to fail. Alicia wanted to fix the process, but her boss opted for a quick fix by changing the ID threshold from 10000 to 100000. This change allowed the process to continue working in its broken state. The underlying issue remained unresolved, and the process still relied on a flawed design. The decision to change the ID threshold was likely made due to dependencies on the existing process.