How to determine when an attribute is changed by calling reflection methods

I have the following class

public class MyClass {
   private int myAttr;

   public void setAttr(int a) { 
      myAttr = a; 
      Thread.dumpStack();
   }
}

Thus, I can detect any attempt to change myAttr. Well, almost anyone. It does not work when someone cheats myAttrusing a method Field.set(). How can I catch the use of Java reflections?

+5
source share
2 answers

You can not. You are in power SecurityManagerif someone is nearby so that someone else does not make trouble against you.

Related question

+5
source

, . , - , . ? , ?

, , , . , ,

    securityManager.checkPermission(ReflectPermission("suppressAccessChecks"))

SecurityException . .

, setAccessible(...) , .

+1

All Articles