Is there is any way to disable reflections for single JVM instance? I'm looking for something like -XX: + DisableExplicitGC
parameter to disable explicit GC calls.
I found this answer , but maybe there is an easier solution. So I can enable or disable reflection without application rebuild.
I'm sure that there are places in the Java class libraries that use reflection so disabling reflection JVM-wide would break those libraries. That's why there's no option like the GC parameter. (Calling explicit GC doesn't affect application behavior, only performance, so disabling it doesn't break anything.)
As far as disabling reflection for just user classes, the java.policy file and/or the java.security file reference that you point to can be done without modifying your app. Those are VM configuration files, not in-app code. I think this is the best that you'll get.