...
Code Block | ||
---|---|---|
| ||
public class MyClass { private static byte[] data; public static byte[] getData() { return data.clone(); } public static void setData(byte[] b) { securityCheck(); data = b.clone(); } } |
However as a cautionary note, simply changing the modifier to final may not prevent attackers from indirectly causing an incorrect value to be stored in the static variable. See Eliminate Class Initialization Cycles for more on this problem.
Risk Assessment
Unauthorized modifications to public static variables can result in unexpected behavior and can bypass important security checks and/or invoke malicious code.
...