Relates :
|
|
Relates :
|
|
Relates :
|
We call "rmic -iiop" to generate a Tie class for our JMX IIOP connector, and we get a NullPointerException time to time from the Tie class when running our unit tests. After having a look at the generated Tie class _RMIConnectionImpl_Tie.java (attached), we find the problem is from the variable "target". This variable can be changed by the methods "setTargetsetTarget" and "deactivate()", and be used directly by the method "_invoke" for a client request. The problem occurs when a thread disconnecting the client calls "setTargetsetTarget" and "deactivate()" to set null to the target, one another thread calling "_invoke" for a client request gets NullPointerException because of null "target". In fact no any synchronization protection for the variable "target". One possible solution is to add a new private method: private Remote returnTarget() throws IOException { final Remote t = target; if (t == null) { // closed? throw new IOException(...); } return t; } and the method "_invoke" gets a "target" instance by calling this method. The same problem appears to jdk1.4 and jdk1.5
|