Changeset 12351


Ignore:
Timestamp:
01/08/10 21:29:41 (11 years ago)
Author:
astalla
Message:

Fixed regression with JavaObject?.javaInstance(Class) and primitive types.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Java.java

    r12345 r12351  
    842842    }
    843843
     844    public static Class<?> maybeBoxClass(Class<?> clazz) {
     845  if(clazz.isPrimitive()) {
     846      return getBoxedClass(clazz);
     847  } else {
     848      return clazz;
     849  }
     850    }
     851   
    844852    private static Class<?> getBoxedClass(Class<?> clazz) {
    845853        if (clazz.equals(int.class)) {
  • trunk/abcl/src/org/armedbear/lisp/JavaObject.java

    r12345 r12351  
    4848    public JavaObject(Object obj) {
    4949        this.obj = obj;
    50   this.intendedClass = obj != null ? obj.getClass() : null;
     50  this.intendedClass =
     51      obj != null ? Java.maybeBoxClass(obj.getClass()) : null;
    5152    }
    5253
    5354    /**
    5455     * Constructs a Java Object with the given intended class, used to access
    55      * the object reflectively.
     56     * the object reflectively. If the class represents a primitive type,
     57     * the corresponding wrapper type is used instead.
    5658     * @throws ClassCastException if the object is not an instance of the
    5759     *                            intended class.
     
    6163      intendedClass = obj.getClass();
    6264  }
    63   if(intendedClass != null && !intendedClass.isInstance(obj)) {
    64       throw new ClassCastException(obj + " can not be cast to " + intendedClass);
     65  if(intendedClass != null) {
     66      intendedClass = Java.maybeBoxClass(intendedClass);
     67      if(!intendedClass.isInstance(obj)) {
     68    throw new ClassCastException(obj + " can not be cast to " + intendedClass);
     69      }
    6570  }
    6671  this.obj = obj;
     
    233238  if(obj == null) {
    234239      return obj;
    235   } else if(c.isAssignableFrom(intendedClass)) {
    236       return obj;
    237240  } else {
    238       return error(new TypeError(intendedClass.getName() + " is not assignable to " + c.getName()));
     241      c = Java.maybeBoxClass(c);
     242      if(c.isAssignableFrom(intendedClass)) {
     243    return obj;
     244      } else {
     245    return error(new TypeError(intendedClass.getName() + " is not assignable to " + c.getName()));
     246      }
    239247  }
    240248    }
Note: See TracChangeset for help on using the changeset viewer.