Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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:

...

Override methods only when necessary. Declare methods and fields final whenever possible to avoid malicious subclassing. When methods and fields cannot be declared final, refrain from increasing the accessibility of overridden methods. (See rule SEC01-J. Minimize the accessibility of classes and their members.)

...

MET04-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].

Risk Assessment

Subclassing allows weakening of access restrictions, which can compromise the security of a Java application.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8b6961b26d2a8fcb-727367d6-461f4fbb-88dc86fa-5f03355591e4b85428006a39"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

[Section 8.4.8.3

http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.8.3], "Requirements in Overriding and Hiding"

]]></ac:plain-text-body></ac:structured-macro>

...