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

  • Full Stack Hands-On Development with .NET

    In the fast-paced realm of modern software development, proficiency across a full stack of technologies is not just beneficial, it's essential. Microsoft has an entire stack of open source development components in its .NET platform (formerly known as .NET Core) that can be used to build an end-to-end set of applications.

  • .NET-Centric Uno Platform Debuts 'Single Project' for 9 Targets

    "We've reduced the complexity of project files and eliminated the need for explicit NuGet package references, separate project libraries, or 'shared' projects."

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

Subscribe on YouTube