title: What is the need of Privileged Block in Reflection
body: <p>I have seen code to get field value through Reflection executed within Privilege block. Following piece of code is taken from <a href="http://svn.apache.org/repos/asf/cxf/trunk/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java" rel="noreferrer"><code>ReflectionUtil</code></a>:</p>
  
  <pre><code>public static &lt;T&gt; T accessDeclaredField(final Field f, final Object o, final Class&lt;T&gt; responseClass) {
      return AccessController.doPrivileged(new PrivilegedAction&lt;T&gt;() {
          public T run() {
              boolean b = f.isAccessible();
              try {
                  f.setAccessible(true);
                  return responseClass.cast(f.get(o));
              } catch (SecurityException e) {
                  return null;
              } catch (IllegalAccessException e) {
                  return null;
              } finally {
                  f.setAccessible(b);
              }
          }
      });
  }
  </code></pre>
  
  <p>I don't understand the reason to get the field value within the privileged block; we can do it without of it. </p>
  
  <p>Is it better coding practice or do we gain something extra?</p>
  
  <p>Ref: <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/doprivileged.html" rel="noreferrer">API for Privileged Blocks</a></p>