Reflection warning: reference to field getClass can't be resolved.

387 views
Skip to first unread message

Vagif Verdi

unread,
Aug 4, 2009, 7:46:08 PM8/4/09
to Clojure
When reflection warning is on, i get 2 warnings on every my file:

reference to field getClass can't be resolved.
reference to field getClassLoader can't be resolved.

Is this something i should be worried about ?

ataggart

unread,
Aug 5, 2009, 3:06:00 AM8/5/09
to Clojure
Probably not. It appears to be in the ns macro:

user=> (set! *warn-on-reflection* true)
true
user=> (ns foo.bar)
Reflection warning, NO_SOURCE_PATH:2 - reference to field getClass
can't be resolved.
Reflection warning, NO_SOURCE_PATH:2 - reference to field
getClassLoader can't be resolved.
nil
foo.bar=>

John Harrop

unread,
Aug 4, 2009, 10:15:02 PM8/4/09
to clo...@googlegroups.com
On Tue, Aug 4, 2009 at 7:46 PM, Vagif Verdi <Vagif...@gmail.com> wrote:

When reflection warning is on, i get 2 warnings on every my file:

reference to field getClass can't be resolved.

That one is very weird, because getClass is a method of java.lang.Object. It should always be possible to resolve that one without reflection.

Laurent PETIT

unread,
Aug 5, 2009, 12:11:16 PM8/5/09
to clo...@googlegroups.com
2009/8/5 John Harrop <jharr...@gmail.com>

getClass is a method ...

Mike Hinchey

unread,
Aug 10, 2009, 3:29:43 AM8/10/09
to clo...@googlegroups.com
This is  nothing to worry about, but it does seem to be something that can be improved in clojure.  I submitted a patch with a simple fix: http://www.assembla.com/spaces/clojure/tickets/171-reflection-warning-from-ns

There is a more complex fix that could be made to the clojure compiler so it would check for both methods and fields before giving the warning.  The InstanceFieldExpr prints this warning because it only checks for a field with the given name.  However, when it evals, it first looks for a method, then a field.  If it did that in the first place, there would be no warning, not just for ns, but user code also.  Should a ticket be filed?

-Mike
Reply all
Reply to author
Forward
0 new messages