JDK-6360330 : NullPointerException from a generated stub: no state check or synchronization protection
  • Type: Bug
  • Component: other-libs
  • Sub-Component: corba:idl
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2005-12-07
  • Updated: 2010-07-29
  • Resolved: 2009-08-26
Related Reports
Relates :  
Relates :  
Relates :  
Description
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

Comments
EVALUATION It's simple enough to synchronize around setTarget, getTarget, and _invoke. Will do this for JDK 7, which will include a new IIOP backend for rmic.
12-08-2006