Encapsulation is about drawing strong boundaries. In a web browser that might mean ensuring that your mobile code cannot be abused by other mobile code. On the server it might mean differentiation between validated data and unvalidated data, between one user's data and another's, or between data users are allowed to see and data that they are not.
public class CustomerServiceApplet extends JApplet
{
public void paint(Graphics g)
{
...
conn = DriverManager.getConnection ("jdbc:mysql://db.example.com/customerDB", "csr", "p4ssw0rd");
...
package
level access to the original outer class. More insidiously, since an inner class can access private
fields in their enclosing class, once an inner class becomes a peer class in bytecode, the compiler converts private
fields accessed by the inner class into protected
fields.
public final class urlTool extends Applet {
private final class urlHelper {
...
}
...
}
finalize()
method public
.super.finalize()
inside an implementation of finalize()
. In mobile code situations, the otherwise error prone practice of manual garbage collection can become a security threat if an attacker can maliciously invoke one of your finalize()
methods because it is declared with public
access. If you are using finalize()
as it was designed, there is no reason to declare finalize()
with anything other than protected
access.public finalize()
method.
public final class urlTool extends Applet {
public void finalize() {
...
}
...
}
public
, final
and static
.public
, final
and static
is a bug. Because arrays are mutable objects, the final
constraint requires that the array object itself be assigned only once, but makes no guarantees about the values of the array elements. Since the array is public, a malicious program can change the values stored in the array. In most situations the array should be made private
.public
, final
and static
.
public final class urlTool extends Applet {
public final static URL[] urls;
...
}
public
but not final
. public
member variables in an Applet and in classes used by an Applet should be declared final
to prevent an attacker from manipulating or gaining unauthorized access to the internal state of the Applet.public
but not final
.
public final class urlTool extends Applet {
public URL url;
...
}