-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: 1.1, 1.2.2, 5.0, 25
-
Component/s: core-libs
-
Fix Understood
-
generic
-
generic
foo/Y.java:
package foo;
class X {
public int i;
}
public class Y extends X {
}
bar/T.java:
package bar;
import foo.Y;
public class T {
public static void main(String[] args) {
Y y = new Y();
int i = y.i;
try {
y.getClass().getField("i").getInt(y);
} catch (Exception e) {
e.printStackTrace();
}
}
}
The Field object from getField has no knowledge that it is accessed through a reference Y.i, which can refer to this field.
At runtime, a workaround is to use MethodHandles.Lookup.findXxx methods, which correctly checks against the referenced class.
- duplicates
-
JDK-8193172 Refection vs Compiler gives different access levels to package-private classes
-
- Closed
-
-
JDK-8371969 Reflection cannot access default method of non-public interface
-
- Closed
-
-
JDK-8133168 Visibility bridge methods cannot be added for final methods
-
- Closed
-
-
JDK-4032740 (Reflection)Accessibilities of members should be ACCESS-LEVEL sensitive.
-
- Closed
-
-
JDK-8181410 Regular accessibility, not reflective access
-
- Closed
-
- relates to
-
JDK-8172815 MethodHandles.Lookup.revealDirect performs access checking against wrong class
-
- Open
-
-
JDK-4071957 (reflect) Method.invoke access control does not understand inner class scoping
-
- Closed
-
-
JDK-8167262 java.lang.IllegalAccessException When Reflecting on Iterator.hasNext()
-
- Closed
-