Checked casts in CNI

Bryce McKinlay mckinlay@redhat.com
Mon Jun 6 16:05:00 GMT 2005


Anthony Green wrote:

>I'm slowly debugging Azureus.
>
>The most recent problem I hit was some CNI code in
>natPlainDatagramSocketImplPosix.cc that was casting a Boolean into a
>InetAddress.  I have a rough patch for this now, but I wonder what other
>bugs like this exist.
>
>I think it would be useful to have a new CNI casting macro that would
>call isAddressableFrom() and throw ClassCastExceptions.
>
>So, instead of 
>
>  addr = (::java::net::InetAddress *) value;
>
>you would write:
>
>  addr = _Jv_CheckedCast (::java::net::InetAddress, value);
>
>or something like that.  What do you think?
>  
>

I think this is a good idea, although it would be even nicer if we could 
make it use the C++-style casting syntax. For example:

addr = java_cast<::java::net::InetAddress> (value);

Note that we already have _Jv_CheckCast() which looks just like what you 
posted above, except it returns a void * pointer and not the actual cast 
type.

Bryce



More information about the Java mailing list