title: Under what situations will Java's field.setAccessible(true) fail?
body: <p>I have a situation where a user's code is throwing an <code>IllegalAccessException</code> on a field accessed by reflection.  Just before accessing the field, <code>setAccessible(true)</code> is called. So, it would seem to me that this method is silently failing.</p>
  
  <p>Under what situations would this happen?  Could this have something to do with a security manager?</p>
  
  <p>Here is the code snippet that is causing the exception:</p>
  
  <pre><code>private static Field levelField;
  public int getLevel() {
      try {
          if (levelField == null) {
              levelField = MessageInfo.class.getDeclaredField("level");
              levelField.setAccessible(true);
          }
          return levelField.getInt(this);  // &lt;-- IllegalAccessException thrown here
      } catch (Exception e) {
           handleException(e);
      }
      return ICompilationUnit.NO_AST;
  }
  </code></pre>