In both "java.lang.reflect.VMField.checkReadAccess" and "java.lang.reflect.VMField.checkWriteAccess" there is an off-by-one error: the parameter to "VM_Class.getClassFromStackFrame" ought to be 3, not 2. This is exemplified by the following stack trace, taken from "TestFieldReflection" (part of the "basic" test suite):
Values:java.lang.IllegalAccessException: Access to < SystemAppCL, Ltest/org/jikesrvm/basic/core/reflect/TestFieldReflection$TypeWithDifferentAccessModifiers; >.mbyte B is denied to java.lang.reflect.Field
at .<invisible method>(Unknown Source:0)
at java.lang.VMThrowable.fillInStackTrace(VMThrowable.java:49)
at java.lang.Throwable.fillInStackTrace(Throwable.java:498)
at java.lang.Throwable.<init>(Throwable.java:159)
at java.lang.Exception.<init>(Exception.java:78)
at java.lang.IllegalAccessException.<init>(IllegalAccessException.java:97)
at java.lang.reflect.JikesRVMSupport.checkAccess(JikesRVMSupport.java:147)
at java.lang.reflect.VMField.checkReadAccess(VMField.java:245)
at java.lang.reflect.VMField.get(VMField.java:57)
at java.lang.reflect.Field.get(Field.java:261)
at test.org.jikesrvm.basic.core.reflect.TestFieldReflection.printFields(TestFieldReflection.java:128)
at test.org.jikesrvm.basic.core.reflect.TestFieldReflection.testFieldReflection(TestFieldReflection.java:75)
at test.org.jikesrvm.basic.core.reflect.TestFieldReflection.testFieldReflection(TestFieldReflection.java:69)
at test.org.jikesrvm.basic.core.reflect.TestFieldReflection.main(TestFieldReflection.java:61)
Here, "test.org.jikesrvm.basic.core.reflect.TestFieldReflection" ought to be considered the accessing class.
FWIW, tracking this rather minor error down was made hard by the fact that the "diffCompareFiles" macro in "build/tests.xml" does not report failures correctly if the "execution" property is not set properly, e.g., during a "tiny" test-run.
Nice catch; thanks!