[armedbear-cvs] r12351 - trunk/abcl/src/org/armedbear/lisp

Alessio Stalla astalla at common-lisp.net
Fri Jan 8 21:29:44 UTC 2010


Author: astalla
Date: Fri Jan  8 16:29:41 2010
New Revision: 12351

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


Modified:
   trunk/abcl/src/org/armedbear/lisp/Java.java
   trunk/abcl/src/org/armedbear/lisp/JavaObject.java

Modified: trunk/abcl/src/org/armedbear/lisp/Java.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Java.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Java.java	Fri Jan  8 16:29:41 2010
@@ -841,6 +841,14 @@
         return false;
     }
 
+    public static Class<?> maybeBoxClass(Class<?> clazz) {
+	if(clazz.isPrimitive()) {
+	    return getBoxedClass(clazz);
+	} else {
+	    return clazz;
+	}
+    }
+    
     private static Class<?> getBoxedClass(Class<?> clazz) {
         if (clazz.equals(int.class)) {
             return Integer.class;

Modified: trunk/abcl/src/org/armedbear/lisp/JavaObject.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/JavaObject.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/JavaObject.java	Fri Jan  8 16:29:41 2010
@@ -47,12 +47,14 @@
 
     public JavaObject(Object obj) {
         this.obj = obj;
-	this.intendedClass = obj != null ? obj.getClass() : null;
+	this.intendedClass =
+	    obj != null ? Java.maybeBoxClass(obj.getClass()) : null;
     }
 
     /**
      * Constructs a Java Object with the given intended class, used to access
-     * the object reflectively.
+     * the object reflectively. If the class represents a primitive type,
+     * the corresponding wrapper type is used instead.
      * @throws ClassCastException if the object is not an instance of the
      *                            intended class.
      */
@@ -60,8 +62,11 @@
 	if(obj != null && intendedClass == null) {
 	    intendedClass = obj.getClass();
 	}
-	if(intendedClass != null && !intendedClass.isInstance(obj)) {
-	    throw new ClassCastException(obj + " can not be cast to " + intendedClass);
+	if(intendedClass != null) {
+	    intendedClass = Java.maybeBoxClass(intendedClass);
+	    if(!intendedClass.isInstance(obj)) {
+		throw new ClassCastException(obj + " can not be cast to " + intendedClass);
+	    }
 	}
 	this.obj = obj;
 	this.intendedClass = intendedClass;
@@ -232,10 +237,13 @@
     public Object javaInstance(Class c) {
 	if(obj == null) {
 	    return obj;
-	} else if(c.isAssignableFrom(intendedClass)) {
-	    return obj;
 	} else {
-	    return error(new TypeError(intendedClass.getName() + " is not assignable to " + c.getName()));
+	    c = Java.maybeBoxClass(c);
+	    if(c.isAssignableFrom(intendedClass)) {
+		return obj;
+	    } else {
+		return error(new TypeError(intendedClass.getName() + " is not assignable to " + c.getName()));
+	    }
 	}
     }
 




More information about the armedbear-cvs mailing list