This is the mail archive of the
kawa@sourceware.cygnus.com
mailing list for the Kawa project.
Bug in coercion?
- To: kawa at sourceware dot cygnus dot com
- Subject: Bug in coercion?
- From: Antonio Leitao <aml at gia dot ist dot utl dot pt>
- Date: 18 Oct 1999 16:35:53 +0100
Hi,
Sorry to bother but I was trying to use the excellent Kawa, version
1.6.60, particularly the invoke-static "generic function" but ran
into a bug. If I understand it correctly, the invoke-static has
problems whenever we want to pass a null as an argument.
After investigation, I found that the real culprit is the function
public Object coerceFromObject (Object obj)
{
if (this == Type.string_type)
return obj.toString();
if (getReflectClass().isAssignableFrom(obj.getClass()))
return obj;
throw new ClassCastException("don't know how to coerce "
+ obj.getClass().getName() + " to "
+ getName());
}
This can be seen by asking kawa to coerce a null to any other pointer
type, such as:
(as <java.lang.String> #!null)
My humble fix is just to check for null values in the beginning of
coerceFromObject, as follows:
public Object coerceFromObject (Object obj)
{
if (obj == null) {
return null;
}
if (this == Type.string_type)
return obj.toString();
if (getReflectClass().isAssignableFrom(obj.getClass()))
return obj;
throw new ClassCastException("don't know how to coerce "
+ obj.getClass().getName() + " to "
+ getName());
}
Then, "everything" works. Of course, it's not entirely correct
because it doesn't even check the validity of the class argument in
(as <fljakdflakj> !#null)
I decided not to go any further because I was not sure I had found the
correct solution (although it worked for me).
Once again, congratulations for the excellent software.
By the way, do you have any plans for better (if that's possible)
integration between Scheme and Java, particularly to allow the
definition of Java subclasses (not only anonymous) in Scheme?
Thanks,
Antonio.