problem with (set! (static-field ...) ...)

castro@lirmm.fr castro@lirmm.fr
Thu Aug 31 01:10:00 GMT 2000


I tried to set! a static field put it turned into a failure.

For the example, I took the fields err and out of
java.lang.System. I know that they are static, but
we can see that we don't get the right error msg.
The same tests can be proceed with an other class
an a non final field

the code:
(define err (static-field <java.lang.System> 'err))
(set! (static-field <java.lang.System> 'out) err)
produces:
java.lang.RuntimeException: no such field out in gnu.bytecode.ClassType
 at gnu.kawa.reflect.SlotSet.apply(SlotSet.java:71)
 at gnu.kawa.reflect.SlotGet.set2(SlotGet.java:136)
 at gnu.kawa.reflect.SlotGet.setN(SlotGet.java:131)
 at gnu.mapping.Setter.applyN(Setter.java:25)
 at gnu.expr.ApplyExp.eval(ApplyExp.java:38)
 at gnu.expr.ModuleExp.evalModule(ModuleExp.java:38)
 at kawa.Shell.run(Shell.java:85)
 at kawa.Shell.run(Shell.java:35)
 at kawa.repl.apply0(repl.java:27)
 at gnu.mapping.Future.run(Future.java:59)

comment:
the first line in OK, we could get the value of System.err

I tried to do the same job using reflections, and it worked normaly:
(define err (static-field <java.lang.System> 'err))
(invoke (invoke (invoke-static <java.lang.Class> 'forName
"java.lang.System")
                        'getDeclaredField 'out) ;; get the System.err
field
            'set
            #!null
            err)
it produced:
java.lang.RuntimeException: java.lang.IllegalAccessException: field is
final
 at gnu.expr.PrimProcedure.applyV(PrimProcedure.java:148)
 at gnu.mapping.MethodProc.applyN(MethodProc.java:80)
 at gnu.kawa.reflect.Invoke.applyN(Invoke.java:124)
 at gnu.kawa.reflect.Invoke.applyN(Invoke.java:49)
 at gnu.expr.ApplyExp.eval(ApplyExp.java:38)
 at gnu.expr.ModuleExp.evalModule(ModuleExp.java:38)
 at kawa.Shell.run(Shell.java:85)
 at kawa.Shell.run(Shell.java:35)
 at kawa.repl.apply0(repl.java:27)
 at gnu.mapping.Future.run(Future.java:59)

comment:
This is the right behavior.



More information about the Kawa mailing list