When tools are too helpful

NetBeans, like so many other IDEs, tries to be helpful. Today it helped by offering me a list of possible remedies to the presence of a Java class in my code for which I did not have a corresponding import. One quick mouse click and that problem disappeared. Then, to help de-clutter my coding window, it collapse the list of imports so that only one line would be consumed instead of 10+.

However, the combination of these two helpful features caused me to waste a lot of time this evening. For ages I could not figure out why my Log4j was creating the output log files, but then completely refusing to put any data into them, preferring instead to display the data on screen.

Frustration ensued as I dug deep into Log4j source, Tomcat JULI source, several diagnostic settings, constant re-checking of the log4j.properties file, the many Jar dependencies and much more. All to no avail.

Finally, while outside of NetBeans, I needed to take a quick look at my source file before embarking on another wild goose chase. What did I see? In the imports section I saw this:

     import java.util.logging.Logger;

when I should be seeing this:

     import org.apache.log4j.Logger;

In the main code this was referred to as just Logger, and since the imports section had been hidden, I didn’t notice that the wrong Logger had been selected. My log files were being set up elsewhere, but when it came time to use the Logger, it was the one that output to the screen instead! That quick mouse click at the start had accidentally selected the wrong one (it only takes a slight slip of the mouse to do this), and the helpful hiding of the imports left me blissfully unaware.

Searching the Web did not turn up any clue to this possible cause, so I document it here in the hope of helping someone else.

Categorised as: Coding

Comment Free Zone

Comments are closed.