title: Disable Java reflection for the current thread
body: <p>I need to call some semi-trustworthy Java code and want to disable the ability to use reflection for the duration of that code's execution. </p>
  
  <pre><code>try{
     // disable reflection somehow
     someObject.method();
  }
  finally{
     // enable reflection again
  }
  </code></pre>
  
  <p>Can this be done with a SecurityManager, and if so, how? </p>
  
  <p><b>Clarification/Context:</b> This is a follow-up to <a href="https://stackoverflow.com/questions/723886/rhino-restrict-java-packages-that-can-be-accessed-from-javascript">another question</a> about restricting the packages that can be called from JavaScript/Rhino. The accepted answer references a blog entry on how to do that, and it requires two steps, the first one using a Rhino API (ClassShutter), the second one turning off reflection and Class.forName(). I was thinking I can do that second step more cleanly using a SecurityManager (learning about SecurityManager, which as has been pointed out, is a complex beast, along the way).</p>
  
  <p>To sum up, I want (from code, not setting file) to turn off Class.forName() and any access to the whole reflection package. </p>