Pass a pointer to JNI_GetCreatedJavaVMs() instead of null

David Holmes david.holmes at
Mon May 7 10:39:40 UTC 2012

On 7/05/2012 7:38 PM, Deven You wrote:
> Hi All,
> There is a potential problem in
> jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp.
> (Maybe it is not suitable for posting this on core-lib, anyone could
> tell me which mailing list is prefer?)
> L85:
> JNI_GetCreatedJavaVMs(&vm, 1, null) in which the 3rd parameter is a
> pointer to an integer. See[1], the latest JNI Invocation API spec does
> not say anything about allowing a null as the last parameter.

The spec doesn't say anything but the implementation does check for 
NULL. I think this is a spec issue rather than a code issue (and I think 
hotspot-runtime owns the JNI spec so cc'ed). It is common practice for 
API's that take pointers like this to say "if buf is not NULL then the 
value of XXX is written into buf". Particularly as in this case there 
will only ever be at most 1 VM created per-process anyway.

I'm more concerned about the fact that the code doesn't even check if 
JNI_GetCreatedVMs returns successfully!


> I think it is more reasonable to change null to an integer variable.
> Here is my fix[2]
> [1]
> [2]
> <>
> Please review this mail!
> Thanks a lot!

More information about the core-libs-dev mailing list