...
Code Block |
---|
|
final class BadSer implements Serializable {
File f;
public BadSer() throws FileNotFoundException {
f = new File("c:\\filepath\\filename");
}
}
|
Compliant
...
Solution (Not Implementing Serializable)
This compliant solution shows a final
class Ser
that does not implement java.io.Serializable
. Consequently, the File
object cannot be serialized.
Code Block |
---|
|
final class Ser {
File f;
public BadSerSer() throws FileNotFoundException {
f = new File("c:\\filepath\\filename");
}
}
|
Compliant Solution (Object Marked Transient)
This compliant solution declares the File
object transient
. Consequently, the file path is not exposed.
Code Block |
---|
|
final class Ser implements Serializable {
transient File f;
public BadSerSer() throws FileNotFoundException {
f = new File("c:\\filepath\\filename");
}
}
|
...