Wednesday, May 17, 2006

Not as private as you may think

ONJava.com -- Subverting Java Access Protection for Unit Testing

Suppose you are planning to design a highly structured programming language, meant to be used in a team environment. You would make sure to have support for private state, which other objects couldn't see -- right?

Would you then go ahead, and add a really simple facility to your language that allowed you to turn off all those access controls?

Well, I'm not sure I would - but Java did. Which turns out to be really nice.

The above article describes how you can get access to private methods and fields. I was using this technique to help me track down a memory leak in a program I'm working on.

I simply kick off my application, open up a BeanShell console to it, and am free to peek inside things like static caches and such.

So nice of Java to offer this back door.

No comments:

Post a Comment