Blasted COM Driver Bug

Okay, so I’ve used the Java Communications API for serial port (RS232) communications quite a bit. Mostly I’m writing java drivers for bar code scanners, specialty printers, and sometimes communicating with an Omron PLC (Process Logic Controller). Anyway, point is, this isn’t new programming to me. I’ve been doing it for about three years now and for the first time I’ve bumped into this bug:

Caught java.lang.NullPointerException: name can’t be null while loading driver com.sun.comm.Win32Driver

A Google search will show that this is actually not an uncommon issue, but for some reason I’ve only recently bumped into it. If I understand correctly, it has to do with the actual loading of the driver (the .dll or on UNIX the .so files) and most proscribed remedies involve directly loading the driver rather than allowing Sun’s CommPortIdentifier class to do it for you.

Well, I’ve tried that and I still get the error, so here’s a better description of my environment: I’m running Avalon Merlin 3.3 as a Windows NT service using the Java Service Wrapper. The Wrapper FAQ even mentions this problem and suggests the solution is in using the correct JVM and making sure the Java library paths are correct. I know I’m using the right JVM (using a JAVA_HOME variable) and I’m explicitly setting the Java library path to include the driver.

Now, here’s some other interesting facts: the bug is repeatable, but doesn’t occur every time on every PC. On some computers, I get the null message on every startup. On other PC’s, I get the message something like once in every 10 startups. Usually when I get the message, the application cannot read from the serial port, but sometimes it can, that is, I get the null error but the app runs just fine. And finally, this only seems to occur when running as a service. When I run via a normal command prompt or even running via the Wrapper in console mode I never see the null exception.

So I’ve tried explicitly loading the driver and also tried numerous configuration and file layout options all to no avail. I’ve thought about switching to the drivers provided by the RXTX project which would then allow this application to run on Linux, but their documentation is sorely lacking. So if anyone has any other suggestions, I’d really love to hear them.