Looking at FieldUtils some more... setAccessible(true) is never rollback with a matching setAccessible(false).
This is a non-trivial side effect. I am wondering whether this side effect should be perpetuated with removing final modifiers: - Should removeFinalModifier have balanced calls to setAccessible()? It does after my change today. - I would like to call removeFinalModifer when forceAccess is true (see my message that started this thread) - Should all FieldUtils methods be balanced? They are not now and my experiment to do so shows that some unit tests fail because they depend on the side effect. Since the side effect is not documented as permanent or transient (to the method call), most Javadocs say that forceAccess means setAccessible(true) but does not specify if this is permanent or temporary. It seems pretty a "leaky" side-effect, for lack of a better term. Thoughts? Gary On Thu, Jan 30, 2014 at 1:46 PM, Gary Gregory <garydgreg...@gmail.com>wrote: > Yes. > > Another issue is that the way the code is currently factored means that > you'd get write access when you only need read... > > Gary > > > -------- Original message -------- > From: Benedikt Ritter > Date:01/30/2014 13:22 (GMT-05:00) > To: Commons Developers List > Subject: Re: [LANG] FieldUtils forceAccess does not force access for final > > So the point you're making is that accessibility alway includes write > access? > > > 2014/1/29 Gary Gregory <garydgreg...@gmail.com> > > > Hi All: > > > > I have a use case where I need to use reflection to set a public static > > final Object. > > > > This does not work with our FieldUtils class because the "forceAccess" > > argument is only used to deal with field visibility by calling > > Field#setAccessible(boolean) > > > > Q1: Should "forceAccess" be expanded to remove the final modifier? Or: > > Q2: Should we add another boolean parameter "forceWrite" to remove the > > FINAL modifier? > > > > I like Q1. > > > > Q3: The Accessible flag is NOT reset if changed after a write! I think it > > should be. Thoughts? > > > > Gary > > > > -- > > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org > > Java Persistence with Hibernate, Second Edition< > > http://www.manning.com/bauer3/> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > > Spring Batch in Action <http://www.manning.com/templier/> > > Blog: http://garygregory.wordpress.com > > Home: http://garygregory.com/ > > Tweet! http://twitter.com/GaryGregory > > > > > > -- > http://people.apache.org/~britter/ > http://www.systemoutprintln.de/ > http://twitter.com/BenediktRitter > http://github.com/britter > -- E-Mail: garydgreg...@gmail.com | ggreg...@apache.org Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory