Pass a pointer to JNI_GetCreatedJavaVMs() instead of null

Alan Bateman Alan.Bateman at
Mon May 7 13:27:43 UTC 2012

On 07/05/2012 11:39, David Holmes wrote:
> 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 agree that the JNI spec needs clarification and it would be 
inconsistent if this function didn't allow this parameter to be NULL. In 
addition it would be incompatible change (and would likely break 
existing code) if the spec were clarified to disallow NULL.

Another point about this JNI function is that it's not clear (to me 
anyway) how it should behave when there isn't a VM. I think HotSpot 
currently returns JNI_OK and sets *nVMs to 0 (if non-NULL).  Assuming 
the JNI spec is clarified to specify existing behavior then passing the 
parameter as NULL just doesn't make sense, meaning JNI_OK does not imply 
that vmBuf[0] is valid.


More information about the core-libs-dev mailing list