This is the mail archive of the kawa@sourceware.cygnus.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug in coercion?


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]