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