Wiki Markup |
---|
Increasing the accessibility of overridden or hidden methods permits a malicious subclass to offer wider access to the restricted method than was originally intended. The access modifier of an overriding or hiding method must provide at least as much access as the overridden or hidden method \[[JLS 2005|AA. Bibliography#JLS 05]\], Section 8.4.8.3, "Requirements in Overriding and Hiding"\]. The following are the allowed accesses: |
...
Code Block | ||
---|---|---|
| ||
class BadScope { protected void doLogic() { System.out.println("Super invoked"); } } public class Sub extends BadScope { public void doLogic() { System.out.println("Sub invoked"); // Do sensitive operations } } |
...
Code Block | ||
---|---|---|
| ||
class BadScope {
protected final void doLogic() { // declare as final
System.out.println("Super invoked");
// Do sensitive operations
}
}
|
...
MET17-EX0: For classes that implement the java.lang.Cloneable
interface, the accessibility of the Object.clone()
method should be increased from protected to public [SCG 2007.
...