Changeset 15570

04/06/22 21:26:55 (3 months ago)
Mark Evenson

Start out with the actual Class in print-object on java:java-object

This prevents jclass-superclass from failing on names (keywords) of
classes generated by jnew-runtime-class (it fails because they are
created in a different ClassLoader? and it can't find them). By passing
an actual Class it doesn't have to do a lookup by name. The fail
occured on the first iteration of the loop in

NB: Yes, jcall works on keywords. So this is working code:

(jcall "getName" :|java.util.List|)
(jclass-superclass :|java.util.HashMap?|)

The inheritance mechanism of print-java-object-by-class is unchanged,
because it internally converts the classes found by jclass-superclass
into a keyword in order to find-method. Before this change, it also
worked because of the above fact that jcall getName works on keywords.

For jnew-runtime-class hierarchies this is fine as well, since the
programmers specialize print-object-by-class themselves on any keywords
they want, so they are responsible for any bugs in that. I.E ABCL's
catch-all print-java-object-by-class doesn't ever call
jclass-superclass on a keyword because the super loop variable there
is always java.lang.Class or nil (that's what jclass-superclass
returns). Before this patch, it was a keyword on the first iteration,
then a java.lang.Class in the rest of the iterations.

Passing a Class is better than passing in a keyword and making it look
up the Class by name (an information loss at the start of the function

  • it goes back to looping on actual Classes after the first iteration

anyway) because it fixes the case of printing instances of
jnew-runtime-class generated classes without having to play around with

2 edited


  • trunk/abcl/src/org/armedbear/lisp/java.lisp

    r15569 r15570  
    460460  (if (jnull-ref-p obj)
    461461      (write-string "#<null>" stream)
    462       (print-java-object-by-class (intern (jclass-name (jobject-class obj)) 'keyword) obj stream)))
     462      (print-java-object-by-class (jobject-class obj) obj stream)))
    464464;;define extensions by eql methods on class name interned in keyword package
  • trunk/abcl/test/lisp/abcl/runtime-class.lisp

    r14903 r15570  
    5454                 "Someone"))
    5555  "Someone")
     57;; print-object
     58(deftest runtime-class.print-object
     59    (subseq
     60     (with-output-to-string (stream)
     61       (print-object
     62        (java:jnew
     63         (java:jnew-runtime-class
     64          "FooList"
     65          :superclass "java.util.AbstractList"
     66          :methods '(("get" "java.lang.Object" (:int)
     67                      (lambda (this index)
     68                        "Foo"))
     69                     ("size" :int ()
     70                      (lambda (this)
     71                        15)))))
     72        stream))
     73     0
     74     20)
     75  "#<FooList [Foo, Foo,")
Note: See TracChangeset for help on using the changeset viewer.