Strange Issue With Static Global Variable in Native

Dan Xu dan.xu at oracle.com
Fri Dec 6 17:22:51 PST 2013


Hi All,

When working on src/solaris/native/sun/net/spi/DefaultProxySelector.c, 
previously I tried to cached a jobject (The cached java object is 
java.net.Proxy.NO_PROXY, which is a special type of Proxy.) as a global 
static variable, no_proxy, in this c file. Its value is initialized in 
the init() native function call. In the following proxy query by calling 
native function, getSystemProxy(), I will just return this no_proxy 
object if no proxy is found.

But strangely, in the case that I return this no_proxy object back to 
java side, the program may throw an ClassCastException saying that the 
object that is passed to java side is a java.io.FileDescriptor instead 
of a java.net.Proxy. The problem only happened in jprt in test, 
java/net/ProxySelector/MultiThreadedSystemProxies.java. If I test it in 
my local linux, it seems always passed.

In addition, instead of caching this special proxy object, I modified my 
change to create no_proxy jobject every time I need by using the same 
code that I previously used to create no_proxy in the init() function. 
And the change can pass the jprt test without any issue. Does anyone 
know why the cached proxy object changed to a FileDescriptor? Thanks!

-Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20131206/49e8d739/attachment.html 


More information about the net-dev mailing list