The dangers of copy-pasta

Copy-paste. It’s easy. It’s fast. You might want to use more brain cells first before blindly doing it.

Years ago I was working for a company that had a customer facing web portal. It was a dashboard that let them manage all their things. It included reporting, graphs, the whole enchilada. In order to manage development costs the company had hired an off-shore team to work on various projects. They’d recently developed a command-line tool for linux that processed XML files. gasp XML! How did the world ever work with such a clunky and clearly despicable markup language!? Sorry, I digress. The tool worked well and offered some functionality that the business folks thought would be good to include in the web portal, so they tasked the same team to port the functionality there. Fast forward a few weeks to when they finished the implementation and delivered it to us to verify before handing over to QA. As we were testing the web portal we all noticed that the site kept on going down. Thankfully it was only in our dev environment. I was assigned this bug and started spelunking through the code. It wasn’t long before I discovered something that just blew my mind. For context, the command-line tool had been written in Java, and our web portal was also Java based. This made porting the functionality fairly easy. However, the dev team had decided to copy-paste most of the code, including their initialization logic. This was a problem. You see, they had a check in the CLI tool that if an xml config file wasn’t present they would display an error message and then they called System.exit(). And they had copy-pasted this code into a Java based web application. Wait for it. Ahhh, there it is! Yes, that’s right, calling that immediately terminated the VM process for the website. Hence, the entire site going down. I got on a call with the remote team to go over my findings and all they had to say was “Oh yeah! Good catch!” and proceeded to chuckle about it. Fortunately, this is a rare fairy tale, with a happy ending. We fixed the code quickly and decided we should probably look for other partners with a more critical eye for detail. 😀

1
+ posts

I am Cranky Old, born four hundred years ago in the Highlands of Scotland. I am Immortal and I am not alone.