Changeset 12570


Ignore:
Timestamp:
03/23/10 12:59:08 (11 years ago)
Author:
Mark Evenson
Message:

Fix JAVA-OBJECT whose tynot being properly coerced to array of primitive types.

Fix proposed by Douglas Miles.

An array of primitive types which were first stuffed into a
type-erasing Java collection and then retrieved could not be used as
the original type.

Updated JAVA-OBJECT's getParts() protocol to return information about
what type the wrapped object thinks it should be.

Added test BUGS.JAVA.1 to test that this has been fixed.

Location:
trunk/abcl
Files:
2 edited

Legend:

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

    r12513 r12570  
    3636import static org.armedbear.lisp.Lisp.*;
    3737
    38 import java.lang.reflect.*;
    39 
     38import java.lang.reflect.Array;
     39import java.lang.reflect.Field;
    4040import java.math.BigInteger;
    41 
    42 import java.util.*;
     41import java.util.ArrayList;
     42import java.util.Collection;
     43import java.util.HashSet;
     44import java.util.LinkedList;
     45import java.util.Set;
    4346
    4447public final class JavaObject extends LispObject {
     
    243246  } else {
    244247      c = Java.maybeBoxClass(c);
    245       if(c.isAssignableFrom(intendedClass)) {
     248      if (c.isAssignableFrom(intendedClass) || c.isInstance(obj)) {
     249              // XXX In the case that c.isInstance(obj) should we then
     250              // "fix" the intendedClass field with the (presumably)
     251              // narrower type of 'obj'?
     252
     253              // ME 20100323: I decided not to because a) we don't
     254              // know the "proper" class to narrow to (i.e. maybe
     255              // there's something "narrower" and b) I'm not sure how
     256              // primitive types relate to their boxed
     257              // representations. 
    246258    return obj;
    247259      } else {
     
    329341  if(obj != null) {
    330342      LispObject parts = NIL;
    331       if(obj.getClass().isArray()) {
    332     SimpleString empty = new SimpleString("");
     343            parts = parts.push(new Cons("Java class",
     344                                        new JavaObject(obj.getClass())));
     345            if (intendedClass != null) {
     346                parts = parts.push(new Cons("intendedClass", new SimpleString(intendedClass.getCanonicalName())));
     347            }
     348      if (obj.getClass().isArray()) {
    333349    int length = Array.getLength(obj);
    334     for(int i = 0; i < length; i++) {
    335         parts = parts.push
    336       (new Cons(empty, JavaObject.getInstance(Array.get(obj, i))));
     350    for (int i = 0; i < length; i++) {
     351        parts = parts
     352                        .push(new Cons(new SimpleString(i),
     353                                       JavaObject.getInstance(Array.get(obj, i))));
    337354    }
    338     parts = parts.nreverse();
    339355      } else {
    340     parts = parts.push(new Cons("Java class",
    341               new JavaObject(obj.getClass())));
    342356    parts = Symbol.NCONC.execute(parts, getInspectedFields());
    343357      }
    344       return parts;
     358      return parts.nreverse();
    345359  } else {
    346360      return NIL;
  • trunk/abcl/test/lisp/abcl/bugs.lisp

    r12417 r12570  
    4040
    4141     
     42(deftest bugs.pathname.1
     43    (namestring (make-pathname :directory '(:relative) :name "file"
     44                   :type :unspecific
     45                   :host nil :device nil))
     46  "./file")
     47
     48(deftest bugs.pathname.2
     49    (TRANSLATE-PATHNAME
     50     #P"/Users/evenson/work/bordeaux-threads/src/bordeaux-threads.abcl"
     51     #P"/**/**/*.*"
     52     #P"/Users/evenson/.cache/common-lisp/armedbear-0.20.0-dev-darwin-unknown/**/*.*")
     53  #P"/Users/evenson/.cache/common-lisp/armedbear-0.20.0-dev-darwin-unknown/bordeaux-threads.abcl")
     54
     55(deftest bugs.pathname.3 
     56    (namestring (MAKE-PATHNAME :HOST NIL :DEVICE NIL
     57                               :DIRECTORY '(:RELATIVE :WILD-INFERIORS)
     58                               :DEFAULTS "/**/"))
     59  "**/")
     60
     61(deftest bugs.java.1
     62    (let* ((a (java:jnew-array "byte" 1))
     63           (b (let ((array-list (java:jnew (java:jconstructor
     64                                       "java.util.ArrayList"))))
     65                (java:jcall (java:jmethod "java.util.AbstractList" "add"
     66                                          "java.lang.Object")
     67                            array-list a)
     68                (java:jcall (java:jmethod "java.util.AbstractList" "get" "int")
     69                            array-list 0))))
     70      (type-of (sys::%make-byte-array-input-stream b)))
     71  stream)
     72               
     73                   
     74                   
Note: See TracChangeset for help on using the changeset viewer.