After having had a look at how you're doing this, would it be possible to generate your "SomeClassName_someFieldName" class as an inner static class of the class containing the members you want to access? This should provide the necessary access to private/protected members.
This approach may be problematic perhaps because the enclosing class (that you want to reflect) should (according to the VM spec) have its inner_classes attribute updated to be aware of any inner classes it references, so these modifications would need to be made before the target class was loaded. If you are going to go to modify the target class in some way before it is loaded, it would probably be more performant to simply change the modifiers of all methods/fields to "public"; this would be less time consuming as the constant pool would not need to be modified/regenerated. You could set a flag to indicate the original accessibility level of the field/method if this is still required. Richard Charles Lloyd wrote: > I am trying to write a replacement for java.lang.reflect.Method and > Field using BCEL. I have everything working nicely except I cannot > figure out how to emulate the setAccessible(true) feature which allows > for access (via reflection) to protected and private Methods and Fields. > > Suggestions or examples greatly appreciated. > > Charles. > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
