DevDisasters

Reverse Psychology

Everything at Henry's company revolved around contracts with vendors. The IT department had relied on the aptly named Contract Manager -- the sole remaining Visual Basic 6 client-server application -- to support that business for the past 12 years.

Contract Manager was a rotten apple in the IT department's orchard of .NET Web apps. Its picky nature kept the company one release behind the latest Windows version, just to be on the safe side. The system's logic was inefficient and tangled, making it a pain to develop and maintain.

The only reason anyone could figure it was still around was because, though old, Contract Manager rarely broke. Rest assured, though, on those rare occurrences when it did break, people noticed.

Break Big or Not at All
"The Contract Manager is crashing!" yelled a voice on the phone. "We can't add new contracts into the system! This is really critical!"

Henry was jarred upright. He wasn't used to these kinds of calls.

"Um, OK. Well, are you getting any error messages?" Henry stammered, but it was of no use -- the line was already dead. Call after call came in and played out the same way.

One user, who followed up with an e-mail after Henry ignored her phone calls, was kind enough to include a screenshot of the error, which pointed to a culprit:

 Integer Overflow on N_CONTRACT_ID.

Henry gulped.

He knew that in Visual Basic 6, integers overflow at 32,768. Could it be that users had managed to exhaust all of the possible Contract ID numbers? Henry quickly checked to confirm his suspicions and sure enough: the 32,768th contract was entered earlier that morning.

Henry knew he could easily fix the code to accept larger IDs, but there was a catch. The Contract Manager .EXE was compiled against a COM+ DLL. This meant Henry had a choice. Fix the COM+ DLL to allow for larger Contract IDs, recompile the client, and force everyone to upgrade the right way (and take forever) … or he could hack it.

Strike That -- Reverse It
Henry had a bold idea. While he was out of positive ID numbers, there were plenty of negative ones. He turned the sequence that generated Contract IDs around, so that it started at -1 and counted down, but that created a new problem.

Contract Manager had huge amounts of business logic in the database, and that meant that it was scattered in dozens of procedures, packages and views. The code to fetch the latest contract resembled the following:

WHERE q.n_contract_id = 
  (SELECT MAX(n_contract_id) FROM contract_rev cr WHERE cr.n_bid = q.n_bid)

So, Henry brute-forced it and replaced all of the SELECT MAXs with this code:

SELECT CASE
  WHEN MIN(n_contract_id) < 0 THEN MIN(n_contract_id)
  ELSE MAX(n_contract_id)
END CASE

Terrible, kludgy and awful, but in the end, it worked! Henry had squeezed another decade out of Contract Manager. He just hoped the system wouldn't be around that long.

About the Author

Mark Bowytz is a contributor to the popular Web site The Daily WTF. He has more than a decade of IT experience and is currently a systems analyst for PPG Industries.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube