It Works On My Machine

      No Comments on It Works On My Machine

As a developer the worst 5 words that can ever come from your mouth is “It Works On My Machine”. Your code works, passes all its tests, but when the client runs it the code fails in some way and you can’t replicate the problem.

No need to wait for a conclusion before the story. Its your fault. Get used to it. It is unlikely that you have discovered a bug in Java or any language you are using. No need to waste time googling “Bugs in Java”. Look at your code, its your fault.

I had such an experience and thanks to the eagle eyes of one of my students the error was found quickly. Here is what happened.

I asked my students to run sample code that will send and receive a plain text email using the Jodd Email library. This program was initially written in 2015 but had not been updated since then. When I reviewed it for use this semester, I had to deal with changes to the Jodd API. Nothing serious, just annoying. With the changes made I ran the code. It only uses a unit test to send and receive. Success, it worked, and so I pushed the update to the repository and told my students about it.

It did not take long to get a report about the unit test failing. How could this be? I ran the code again and it worked fine for me “on my machine”. This is where a student spotted the problem. In the unit test I had a line that read:

mailBeanSend.getToField().add(“cst.receive@gmail.com");

I had used a literal string to define the To: field. The problem was that this address was going to be different for every student as they were told to use their Gmail accounts. The repo had my Gmail credentials removed. By neglecting this line I had a program that could only pass its test if it’s To: field read “cst.receive@gmail.com” which is what I used. Therefore, it always worked on my machine.

The fix was easy. The new line reads:

mailBeanSend.getToField().add(receiveConfigBean.getUserEmailAddress());

Case closed. Another case of “It works on my machine” resolved.

About Ken Fogel

Java Champion, JCP Executive Committee Member and NetBeans Dream Team Member. Java One/Code One speaker. Organizer of DawsCon, Montreal's free one day software conference. Next conference is January 10, 2020. Faculty member of the Computer Science Technology Program at Dawson College, Montreal. Instructor at the Continuing Education Computer Institute of Concordia University, Montreal. Passionate about teaching and inspiring students to be better programmers.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.