Commit 2f4ad123 authored by mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f's avatar mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f
Browse files

jss: GET-JAVA-FIELD now finds non-public inherited fields with TRY-HARDER.

Robert Goldman contributes in <http://abcl.org/trac/ticket/362>:

GET-JAVA-FIELD, when its optional TRY-HARDER argument is NIL, will
return any public field on its argument object, whether defined
locally or inherited.

When TRY-HARDER argument is true, on the other hand, it will return
non-public fields as well as public ones but only non-public fields
that are defined locally -- not non-public fields that are inherited.

This non-orthogonality seems wrong (just read the contorted
description above and imagine it as a docstring!). I am attaching a
proposed patch which searches up the class hierarchy to find inherited
non-public fields when TRY-HARDER is true.
parent 9ae81da9
......@@ -325,8 +325,9 @@ If OBJECT is a symbol it names a dot qualified static FIELD."
(jobject-class object))))
(jfield (if (java-object-p field)
field
(find field (#"getDeclaredFields" class)
:key 'jfield-name :test 'equal))))
(or (find-declared-field field class)
(error "Unable to find a FIELD named ~a for ~a"
field object)))))
(#"setAccessible" jfield +true+)
(values (#"get" jfield object) jfield))
(if (symbolp object)
......@@ -334,6 +335,23 @@ If OBJECT is a symbol it names a dot qualified static FIELD."
(jfield class field))
(jfield field object))))
(defun find-declared-field (field class)
"Return a FIELD object corresponding to the definition of FIELD
\(a string\) visible at CLASS. *Not* restricted to public classes, and checks
all superclasses of CLASS.
Returns NIL if no field object is found."
(loop while class
for field-obj = (get-declared-field class field)
if field-obj
do (return-from find-declared-field field-obj)
else
do (setf class (jclass-superclass class)))
nil)
(defun get-declared-field (class fieldname)
(find fieldname (#"getDeclaredFields" class)
:key 'jfield-name :test 'equal))
;; TODO use #"getSuperclass" and #"getInterfaces" to see whether there
;; are fields in superclasses that we might set
(defun set-java-field (object field value &optional (try-harder *running-in-osgi*))
......
;;;; -*- Mode: LISP -*-
(asdf:defsystem :jss
:author "Alan Ruttenberg, Mark Evenson"
:version "3.0.7"
:description "<> asdf:defsystem <urn:abcl.org/release/1.3.0/contrib/jss#3.0.7"
:version "3.0.8"
:description "<> asdf:defsystem <urn:abcl.org/release/1.4.0/contrib/jss#3.0.8"
:components ((:module base
:pathname "" :serial t
:components ((:file "packages")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment