Solved

Using javax.comm in Java 1.2 applets

Posted on 2000-03-12
4
373 Views
Last Modified: 2008-03-04
I am trying to get access to a PC's serial ports from a signed Java applet, using the Java 1.2.2 plug-in for IE5 and the Java Comms API v2.0. I have copied the win32com.dll, comm.jar and properties file to the appropriate places for the right runtime environment on the client PC, and granted all permissions to applets signed by me. In the applet, I use getCommPortIdentifiers to get an enumerator, then use this to obtain all available serial ports. However, when the applet is loaded, the following error is reported when I execute the hasMoreElements() method of the enumerator:
"Caught java.lang.NullPointerException: name can't be null while loading driver com.sun.comm.Win32Driver"

The same code works fine when run as an application. The security setup is definitely having an effect, since I also try to read from a local file - this fails as expected when the applet is unsigned (and the comm port stuff raises a different seurity-related error, too) but succeeds when the applet is signed. Perhaps I have missed something else though.

If anyone has any ideas on how to proceed, I would be glad to hear them.

Many thanks,
Chris
0
Comment
Question by:chrisgresty
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 75 total points
ID: 2611362
it seems that JavaComm can't configure itself.

the only thing I can suggest is to decompile the JavaComm classes and add some additional logging.

you can find the code that prints the error message inside javax.comm.CommPortIdentifier.java

try
{
    CommDriver commdriver = (CommDriver)Class.forName(s1).newInstance();
    commdriver.initialize();
}
catch(Throwable throwable)
{
    System.err.println("Caught " + throwable + " while loading driver " + s1);
}

the real problem is somewhere inside com.sun.comm.Win32Driver
0
 

Author Comment

by:chrisgresty
ID: 2612215
Thanks heyhey_, you pointed me in the right direction. There is a problem during the static initialisation of CommPortIdentifier. During this, the following lines are executed:

loadDriver(s1);
propfilename = new String(s1);

(s1 is the javax.comm.properties file)

As part of the driver initialisation started by loadDriver, the addPortName() method is called. If there is a security manager being used, it checks the delete permission on propfilename. Which hasn't been initialised yet. Whoops.

So initialisation fails whenever you use javax.comm with a security manager.

Switching the two lines around solves this problem. I can't see any negative implications of this yet...
0
 

Author Comment

by:chrisgresty
ID: 2615237
Heyhey_'s comments gave me a handle on the problem, and led me to find the right answer - thanks!
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2615709
thank you :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 48
Problem to Alipay 10 67
wild fly 8 startup error 2 37
DTD and JAVA versions 1 27
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question