This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to prevent reflection to access private methods and members in java classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to prevent reflection to access private methods and members in java classes?" Watch "How to prevent reflection to access private methods and members in java classes?" New topic
Author

How to prevent reflection to access private methods and members in java classes?

agilemanoj kumar
Ranch Hand

Joined: Mar 07, 2008
Posts: 70
Private members and methods can be accessed by outer world using reflection concept in java.

Please have a look on http://www.onjava.com/pub/a/onjava/2003/11/12/reflection.html this link. This link gives the information about REFLECTION which can be used to access private methods and it is well explained.

Now my question is How to prevent reflection to access private methods and members in java classes?


Manoj Kumar
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

You will need to use the security manager; see the Security Features in Java SE tutorial to start with. This is how applets are prevented from accessing local files, and from using reflection to get around these limits.

In particular, setAccessible(true) checks for ReflectPermission("suppressAccessChecks") before allowing access to private members.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to prevent reflection to access private methods and members in java classes?
 
Similar Threads
Reflection API...
Single Out A Class Responsible for a Certain Task By Reflection
Usage Of Accessing private Members Through Reflection
Testing private methods using Reflection API
got private variables :(